Documentation ¶
Index ¶
- Constants
- type FileOutputOpt
- type Logger
- func (l *Logger) AddCore(core ...zapcore.Core)
- func (l *Logger) Debug(msg string, vs ...any)
- func (l *Logger) Error(vs ...any)
- func (l *Logger) Flush()
- func (l *Logger) Info(msg string, vs ...any)
- func (l *Logger) Lv() int8
- func (l *Logger) NewFileOutput(opts ...FileOutputOpt)
- func (l *Logger) NewOutput(writer io.Writer)
- func (l *Logger) SetLv(lv int8)
- func (l *Logger) Warn(msg string, vs ...any)
- type Option
- type Options
- type OutFileOptions
Constants ¶
View Source
const ( DebugLv = zapcore.DebugLevel InfoLv = zapcore.InfoLevel WarnLv = zapcore.WarnLevel ErrorLv = zapcore.ErrorLevel )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileOutputOpt ¶
type FileOutputOpt func(*OutFileOptions)
FileOutputOpt 文件输出选项
func WithCompress ¶
func WithCompress(compress bool) FileOutputOpt
func WithFilename ¶
func WithFilename(filename string) FileOutputOpt
func WithLocalTime ¶
func WithLocalTime(localTime bool) FileOutputOpt
func WithMaxAge ¶
func WithMaxAge(maxAge int) FileOutputOpt
func WithMaxBackups ¶
func WithMaxBackups(maxBackups int) FileOutputOpt
func WithMaxSize ¶
func WithMaxSize(maxSize int) FileOutputOpt
type Logger ¶
type Logger struct { // 日志打印用 Logger zap.SugaredLogger *Options // contains filtered or unexported fields }
Logger 是对 zap.SugaredLogger 的封装,简化其对外使用的接口, 并且针对于 Logger 所有配置都是支持运行时动态修改,且并发安全。 Logger 也支持了针对于 zapcore.Core 的扩展,调用 Logger.AddCore 即可,
构建该对象请使用 New 进行创建,在该操作中会对部分必要属性进行初始化, 直接使用结构体创建会导致结构体不可用(甚至panic)。
如非深度定制化扩展,非必要不建议使用 Logger.AddCore 进行扩展,该操作会 导致客户端应用程序对zap包编译依赖,不保证切换内部日志实现。
func GetInstance ¶
func GetInstance() *Logger
func (*Logger) Error ¶
Error 打印错误级别日志 该方法具有两种传参形式:
- error类型:会直接格式化打印%+v日志
- 信息(格式化)
- error+格式化信息:error会作为 With 格式存在,且依旧以%+v格式输出
func (*Logger) NewFileOutput ¶
func (l *Logger) NewFileOutput(opts ...FileOutputOpt)
NewFileOutput 新增日志输出文件配置
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
func (Options) SkipCaller ¶
type OutFileOptions ¶
type OutFileOptions struct {
// contains filtered or unexported fields
}
func (OutFileOptions) Compress ¶
func (options OutFileOptions) Compress() bool
func (OutFileOptions) Filename ¶
func (options OutFileOptions) Filename() string
func (OutFileOptions) LocalTime ¶
func (options OutFileOptions) LocalTime() bool
func (OutFileOptions) MaxAge ¶
func (options OutFileOptions) MaxAge() int
func (OutFileOptions) MaxBackups ¶
func (options OutFileOptions) MaxBackups() int
func (OutFileOptions) MaxSize ¶
func (options OutFileOptions) MaxSize() int
Click to show internal directories.
Click to hide internal directories.