Documentation ¶
Overview ¶
Package logger is log library encapsulated in https://github.com/uber-go/zap
Support for terminal printing and log saving. Support for automatic log file cutting. Support for json format and console log format output. Supports Debug, Info, Warn, Error, Panic, Fatal, also supports fmt.Printf-like log printing, 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 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 Warn(msg string, fields ...Field)
- func Warnf(format string, a ...interface{})
- func WithFields(fields ...Field) *zap.Logger
- 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 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 Uint64(key string, val uint64) Field
- func Uintptr(key string, val uintptr) Field
- type FileOption
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetWithSkip ¶
GetWithSkip get defaultLogger, set the skipped caller value, customize the number of lines of code displayed
func Init ¶
Init initial log settings print the debug level log in the terminal, example: Init() print the info level log in the terminal, example: Init(WithLevel("info")) print the json format, debug level log in the terminal, example: Init(WithFormat("json")) log with hooks, example: Init(WithHooks(func(zapcore.Entry) error{return nil})) output the log to the file out.log, using the default cut log-related parameters, debug-level log, example: Init(WithSave()) output the log to the specified file, custom set the log file cut log parameters, json format, debug level log, example: Init(
WithFormat("json"), WithSave(true, WithFileName("my.log"), WithFileMaxSize(5), WithFileMaxBackups(5), WithFileMaxAge(10), WithFileIsCompression(true), ))
func ReplaceGRPCLoggerV2 ¶ added in v1.4.5
ReplaceGRPCLoggerV2 replace grpc logger v2
func Sync ¶ added in v1.5.4
func Sync() error
Sync flushing any buffered log entries, applications should take care to call Sync before exiting.
func WithFields ¶
WithFields carrying field information
Types ¶
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)