Documentation
¶
Index ¶
- Variables
- func Close() error
- func Debug(msg string, keysAndValues ...interface{})
- func Error(msg string, keysAndValues ...interface{})
- func Fatal(msg string, keysAndValues ...interface{})
- func Info(msg string, keysAndValues ...interface{})
- func Init(opts *Options) error
- func NewLogger(opts *Options) *zapLogger
- func Panic(msg string, keysAndValues ...interface{})
- func Reset()
- func Sync()
- func Warning(msg string, keysAndValues ...interface{})
- type Logger
- type Options
- type RotateConfig
- type RotateWriter
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrRotateWriterClosed = errors.New("rotate writer is closed")
ErrRotateWriterClosed 表示向已关闭的轮转写入器写入日志.
Functions ¶
func Close ¶ added in v0.1.3
func Close() error
Close 关闭日志文件. 全局 Close 是引用计数的:每次 Init 计一次,Close 递减,归零时才真正关闭轮转文件.
func NewLogger ¶
func NewLogger(opts *Options) *zapLogger
NewLogger 根据传入的 opts 创建 Logger. 为了保持向后兼容,该接口不返回错误:初始化失败时会输出到 stderr 并回退为 stdout logger. 需要感知初始化失败(如日志目录不可写)请使用 Init.
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) Logger
Sync()
Close()
}
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 包含与日志相关的配置项.
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, error)
NewRotateWriter 创建一个新的轮转写入器. 首次打开日志文件失败时返回错误,调用方(log.Init)应向上传播该错误,做到 fail-loud.
func (*RotateWriter) Close ¶ added in v0.1.2
func (w *RotateWriter) Close() error
Close 关闭当前日志文件,可重复调用
Click to show internal directories.
Click to hide internal directories.