log

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func C

func C(ctx context.Context) *zapLogger

C 解析传入的 context,尝试提取关注的键值,并添加到 zap.Logger 结构化日志中.

func Debug

func Debug(msg string, keysAndValues ...interface{})

Debug 输出 debug 级别的日志.

func Error

func Error(msg string, keysAndValues ...interface{})

Error 输出 error 级别的日志.

func Fatal

func Fatal(msg string, keysAndValues ...interface{})

Fatal 输出 fatal 级别的日志.

func Info

func Info(msg string, keysAndValues ...interface{})

Info 输出 info 级别的日志.

func Init

func Init(opts *Options)

Init 使用指定的选项初始化 Logger.

func NewLogger

func NewLogger(opts *Options) *zapLogger

NewLogger 根据传入的 opts 创建 Logger.

func Panic

func Panic(msg string, keysAndValues ...interface{})

Panic 输出 panic 级别的日志.

func Sync

func Sync()

Sync 调用底层 zap.Logger 的 Sync 方法,将缓存中的日志刷新到磁盘文件中. 主程序需要在退出前调用 Sync.

func Warning

func Warning(msg string, keysAndValues ...interface{})

Warning 输出 warning 级别的日志.

Types

type Logger

type Logger interface {
	Debug(msg string, keysAndValues ...interface{})
	Info(msg string, keysAndValues ...interface{})
	Warning(msg string, keysAndValues ...interface{})
	Error(msg string, keysAndValues ...interface{})
	Panic(msg string, keysAndValues ...interface{})
	Fatal(msg string, keysAndValues ...interface{})
	C(ctx context.Context) *zapLogger
	Sync()
}

Logger 定义了 biddingAI 项目的日志接口. 该接口只包含了支持的日志记录方法.

type Options

type Options struct {
	// 是否开启 caller,如果开启会在日志中显示调用日志所在的文件和行号
	DisableCaller bool
	// 是否禁止在 panic 及以上级别打印堆栈信息
	DisableStacktrace bool
	// 指定日志级别,可选值:debug, info, warn, error, dpanic, panic, fatal
	Level string
	// 指定日志显示格式,可选值:console, json
	Format string
	// 指定日志输出位置
	OutputPaths []string
	// 日志轮转配置,如果不为 nil 则启用日志轮转
	Rotation *RotateConfig
}

Options 包含与日志相关的配置项.

func NewOptions

func NewOptions() *Options

NewOptions 创建一个带有默认参数的 Options 对象.

type RotateConfig added in v0.1.2

type RotateConfig struct {
	// 按时间轮转:daily(每天), hourly(每小时)
	Interval string // 默认 daily
	// 日志文件基础路径,实际文件名为 ${BasePath}.YYYYMMDD.log
	BasePath string
	// 是否同时输出到 stdout
	Stdout bool // 默认 true
}

RotateConfig 日志轮转配置

type RotateWriter added in v0.1.2

type RotateWriter struct {
	// contains filtered or unexported fields
}

RotateWriter 按时间轮转的日志写入器

func NewRotateWriter added in v0.1.2

func NewRotateWriter(basePath, interval string) *RotateWriter

NewRotateWriter 创建一个新的轮转写入器

func (*RotateWriter) Close added in v0.1.2

func (w *RotateWriter) Close() error

Close 关闭当前日志文件

func (*RotateWriter) Sync added in v0.1.2

func (w *RotateWriter) Sync() error

Sync 同步日志到磁盘

func (*RotateWriter) Write added in v0.1.2

func (w *RotateWriter) Write(p []byte) (n int, err error)

Write 实现 io.Writer 接口

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL