Documentation
¶
Overview ¶
Package logger 是封装在 https://github.com/uber-go/zap 中的日志库
支持终端打印和日志保存 支持自动日志文件切割 支持 JSON 格式和控制台日志格式输出 支持 Debug, Info, Warn, Error, Panic, Fatal,也支持类似 fmt.Printf 的日志打印,Debugf, Infof, Warnf, Errorf, Panicf, Fatalf
Index ¶
- func Debug(msg string, fields ...Field)
- func Debugf(format string, a ...interface{})
- func Error(msg string, fields ...Field)
- func Errorf(format string, a ...interface{})
- func Fatal(msg string, fields ...Field)
- func Fatalf(format string, a ...interface{})
- func GGetFieldValue(field Field) interface{}
- func Get() *zap.Logger
- func GetWithSkip(skip int) *zap.Logger
- func Info(msg string, fields ...Field)
- func Infof(format string, a ...interface{})
- func Init(opts ...Option) (*zap.Logger, error)
- func Panic(msg string, fields ...Field)
- func ReplaceGRPCLoggerV2(l *zap.Logger)
- func Sync() error
- func ToJSON(fields []zap.Field) string
- func Warn(msg string, fields ...Field)
- func Warnf(format string, a ...interface{})
- type CustomHook
- type Field
- func Any(key string, val interface{}) Field
- func Bool(key string, val bool) Field
- func Duration(key string, val time.Duration) Field
- func Err(err error) Field
- func Float64(key string, val float64) Field
- func Int(key string, val int) Field
- func Int32(key string, val int32) Field
- func Int64(key string, val int64) Field
- func String(key string, val string) Field
- func Stringer(key string, val fmt.Stringer) Field
- func Time(key string, val time.Time) Field
- func Uint(key string, val uint) Field
- func Uint32(key string, val uint32) Field
- func Uint64(key string, val uint64) Field
- func Uintptr(key string, val uintptr) Field
- type FileOption
- func WithFileIsCompression(isCompression bool) FileOption
- func WithFileMaxAge(maxAge int) FileOption
- func WithFileMaxBackups(maxBackups int) FileOption
- func WithFileMaxSize(maxSize int) FileOption
- func WithFileName(filename string) FileOption
- func WithLocalTime(isLocalTime bool) FileOption
- func WithNoPrint(noPrint bool) FileOption
- func WithSaveDay(isSaveDay bool) FileOption
- type Option
- func WithAsync(enabled bool) Option
- func WithAsyncBufferSize(size int) Option
- func WithAsyncFlushInterval(interval time.Duration) Option
- func WithCustomHooks(hooks ...CustomHook) Option
- func WithFormat(format string) Option
- func WithHooks(hooks ...func(zapcore.Entry) error) Option
- func WithLevel(levelName string) Option
- func WithSave(isSave bool, opts ...FileOption) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GGetFieldValue ¶ added in v1.3.12
func GGetFieldValue(field Field) interface{}
func GetWithSkip ¶
GetWithSkip 获取 defaultLogger,设置跳过的调用者值,自定义显示的代码行数
func Init ¶
Init 初始化日志设置 在终端打印 debug 级别日志,示例: Init() 在终端打印 info 级别日志,示例: Init(WithLevel("info")) 在终端打印 json 格式,debug 级别日志,示例: Init(WithFormat("json")) 带钩子的日志,示例: Init(WithHooks(func(zapcore.Entry) error{return nil})) 输出日志到文件 out.log,使用默认切割日志相关参数,debug 级别日志,示例: Init(WithSave()) 输出日志到指定文件,自定义设置日志文件切割参数,json 格式,debug 级别日志,示例: Init(
WithFormat("json"),
WithSave(true,
WithFileName("my.log"),
WithFileMaxSize(5),
WithFileMaxBackups(5),
WithFileMaxAge(10),
WithFileIsCompression(true),
))
func ReplaceGRPCLoggerV2 ¶
ReplaceGRPCLoggerV2 replace grpc logger v2
Types ¶
type CustomHook ¶ added in v1.3.12
CustomHook defines a custom hook function that can access log level, message and fields
type Field ¶
Field type
type FileOption ¶
type FileOption func(*fileOptions)
FileOption set the file options.
func WithFileIsCompression ¶
func WithFileIsCompression(isCompression bool) FileOption
WithFileIsCompression set whether to compress log files
func WithFileMaxAge ¶
func WithFileMaxAge(maxAge int) FileOption
WithFileMaxAge set maximum number of days for old documents
func WithFileMaxBackups ¶
func WithFileMaxBackups(maxBackups int) FileOption
WithFileMaxBackups set maximum number of old files
func WithFileMaxSize ¶
func WithFileMaxSize(maxSize int) FileOption
WithFileMaxSize set maximum file size (MB)
func WithLocalTime ¶ added in v1.1.18
func WithLocalTime(isLocalTime bool) FileOption
WithLocalTime set whether to use local time
func WithNoPrint ¶ added in v1.3.2
func WithNoPrint(noPrint bool) FileOption
func WithSaveDay ¶ added in v1.1.50
func WithSaveDay(isSaveDay bool) FileOption
type Option ¶
type Option func(*options)
Option set the logger options.
func WithAsyncBufferSize ¶ added in v1.4.3
WithAsyncBufferSize sets the buffer size for asynchronous logging (in bytes)
func WithAsyncFlushInterval ¶ added in v1.4.3
WithAsyncFlushInterval sets the flush interval for asynchronous logging
func WithCustomHooks ¶ added in v1.3.12
func WithCustomHooks(hooks ...CustomHook) Option
WithCustomHooks sets custom hooks that can access fields data
func WithFormat ¶
WithFormat set the output log format, console or json