Documentation ¶
Index ¶
- Constants
- func DPanic(args ...any)
- func DPanicContext(ctx context.Context, args ...any)
- func DPanicf(template string, args ...any)
- func DPanicfContext(ctx context.Context, template string, args ...any)
- func DPanicw(msg string, keysAndValues ...any)
- func DPanicwContext(ctx context.Context, msg string, keysAndValues ...any)
- func DPanicx(msg string, fields ...Field)
- func DPanicxContext(ctx context.Context, msg string, fields ...Field)
- func Debug(args ...any)
- func DebugContext(ctx context.Context, args ...any)
- func Debugf(template string, args ...any)
- func DebugfContext(ctx context.Context, template string, args ...any)
- func Debugw(msg string, keysAndValues ...any)
- func DebugwContext(ctx context.Context, msg string, keysAndValues ...any)
- func Debugx(msg string, fields ...Field)
- func DebugxContext(ctx context.Context, msg string, fields ...Field)
- func Enabled(lvl Level) bool
- func Error(args ...any)
- func ErrorContext(ctx context.Context, args ...any)
- func Errorf(template string, args ...any)
- func ErrorfContext(ctx context.Context, template string, args ...any)
- func Errorw(msg string, keysAndValues ...any)
- func ErrorwContext(ctx context.Context, msg string, keysAndValues ...any)
- func Errorx(msg string, fields ...Field)
- func ErrorxContext(ctx context.Context, msg string, fields ...Field)
- func Fatal(args ...any)
- func FatalContext(ctx context.Context, args ...any)
- func Fatalf(template string, args ...any)
- func FatalfContext(ctx context.Context, template string, args ...any)
- func Fatalw(msg string, keysAndValues ...any)
- func FatalwContext(ctx context.Context, msg string, keysAndValues ...any)
- func Fatalx(msg string, fields ...Field)
- func FatalxContext(ctx context.Context, msg string, fields ...Field)
- func Info(args ...any)
- func InfoContext(ctx context.Context, args ...any)
- func Infof(template string, args ...any)
- func InfofContext(ctx context.Context, template string, args ...any)
- func Infow(msg string, keysAndValues ...any)
- func InfowContext(ctx context.Context, msg string, keysAndValues ...any)
- func Infox(msg string, fields ...Field)
- func InfoxContext(ctx context.Context, msg string, fields ...Field)
- func Logger() *zap.Logger
- func Panic(args ...any)
- func PanicContext(ctx context.Context, args ...any)
- func Panicf(template string, args ...any)
- func PanicfContext(ctx context.Context, template string, args ...any)
- func Panicw(msg string, keysAndValues ...any)
- func PanicwContext(ctx context.Context, msg string, keysAndValues ...any)
- func Panicx(msg string, fields ...Field)
- func PanicxContext(ctx context.Context, msg string, fields ...Field)
- func PoolGet() *fieldContainer
- func PoolPut(c *fieldContainer)
- func ReplaceGlobals(logger *Log)
- func SetLevelWithText(text string) error
- func Sugar() *zap.SugaredLogger
- func Sync() error
- func V(lvl Level) bool
- func Warn(args ...any)
- func WarnContext(ctx context.Context, args ...any)
- func Warnf(template string, args ...any)
- func WarnfContext(ctx context.Context, template string, args ...any)
- func Warnw(msg string, keysAndValues ...any)
- func WarnwContext(ctx context.Context, msg string, keysAndValues ...any)
- func Warnx(msg string, fields ...Field)
- func WarnxContext(ctx context.Context, msg string, fields ...Field)
- type AtomicLevel
- type CallerCore
- func (c *CallerCore) AddSkip(callerSkip int) *CallerCore
- func (c *CallerCore) AddSkipPackage(vs ...string) *CallerCore
- func (c *CallerCore) Enabled(lvl Level) bool
- func (c *CallerCore) Level() Level
- func (c *CallerCore) SetLevel(lv Level) *CallerCore
- func (c *CallerCore) UnderlyingLevel() AtomicLevel
- func (c *CallerCore) UseExternalLevel(l AtomicLevel) *CallerCore
- type Config
- type Field
- func Any(key string, val any) Field
- func Binary(key string, val []byte) Field
- func Bool(key string, val bool) Field
- func Boolp(key string, val *bool) Field
- func ByteString(key string, val []byte) Field
- func Complex128(key string, val complex128) Field
- func Complex128p(key string, val *complex128) Field
- func Complex64(key string, val complex64) Field
- func Complex64p(key string, val *complex64) Field
- func DefaultCaller(depth int, skipPackages ...string) Field
- func DefaultCallerFile(depth int, skipPackages ...string) Field
- func Dict(key string, val ...Field) Field
- func Duration(key string, val time.Duration) Field
- func Durationp(key string, val *time.Duration) Field
- func Err(val error) Field
- func Errors(key string, val []error) Field
- func Float32(key string, val float32) Field
- func Float32p(key string, val *float32) Field
- func Float64(key string, val float64) Field
- func Float64p(key string, val *float64) Field
- func Inline(val ObjectMarshaler) Field
- func Int(key string, val int) Field
- func Int16(key string, val int16) Field
- func Int16p(key string, val *int16) Field
- func Int32(key string, val int32) Field
- func Int32p(key string, val *int32) Field
- func Int64(key string, val int64) Field
- func Int64p(key string, val *int64) Field
- func Int8(key string, val int8) Field
- func Int8p(key string, val *int8) Field
- func Intp(key string, val *int) Field
- func NamedError(key string, val error) Field
- func Namespace(key string) Field
- func Object(key string, val ObjectMarshaler) Field
- func Reflect(key string, val any) Field
- func Skip() Field
- func Stack(key string) Field
- func StackSkip(key string, skip int) Field
- func String(key string, val string) Field
- func Stringer(key string, val fmt.Stringer) Field
- func Stringp(key string, val *string) Field
- func Time(key string, val time.Time) Field
- func Timep(key string, val *time.Time) Field
- func Uint(key string, val uint) Field
- func Uint16(key string, val uint16) Field
- func Uint16p(key string, val *uint16) Field
- func Uint32(key string, val uint32) Field
- func Uint32p(key string, val *uint32) Field
- func Uint64(key string, val uint64) Field
- func Uint64p(key string, val *uint64) Field
- func Uint8(key string, val uint8) Field
- func Uint8p(key string, val *uint8) Field
- func Uintp(key string, val *uint) Field
- func Uintptr(key string, val uintptr) Field
- func Uintptrp(key string, val *uintptr) Field
- type Level
- type Log
- func AddCallerSkip(callerSkip int) *Log
- func AddCallerSkipPackage(vs ...string) *Log
- func Named(name string) *Log
- func NewLogger(opts ...Option) *Log
- func NewLoggerWith(logger *zap.Logger, lv AtomicLevel) *Log
- func SetCallerLevel(lv Level) *Log
- func SetDefaultValuer(vs ...Valuer) *Log
- func SetLevel(lv Level) *Log
- func UseExternalCallerLevel(lvl AtomicLevel) *Log
- func With(fields ...Field) *Log
- func WithNewValuer(fs ...Valuer) *Log
- func WithValuer(vs ...Valuer) *Log
- func (l *Log) AddCallerSkip(callerSkip int) *Log
- func (l *Log) AddCallerSkipPackage(vs ...string) *Log
- func (l *Log) DPanic(args ...any)
- func (l *Log) DPanicContext(ctx context.Context, args ...any)
- func (l *Log) DPanicf(template string, args ...any)
- func (l *Log) DPanicfContext(ctx context.Context, template string, args ...any)
- func (l *Log) DPanicw(msg string, keysAndValues ...any)
- func (l *Log) DPanicwContext(ctx context.Context, msg string, keysAndValues ...any)
- func (l *Log) DPanicx(msg string, fields ...Field)
- func (l *Log) DPanicxContext(ctx context.Context, msg string, fields ...Field)
- func (l *Log) Debug(args ...any)
- func (l *Log) DebugContext(ctx context.Context, args ...any)
- func (l *Log) Debugf(template string, args ...any)
- func (l *Log) DebugfContext(ctx context.Context, template string, args ...any)
- func (l *Log) Debugw(msg string, keysAndValues ...any)
- func (l *Log) DebugwContext(ctx context.Context, msg string, keysAndValues ...any)
- func (l *Log) Debugx(msg string, fields ...Field)
- func (l *Log) DebugxContext(ctx context.Context, msg string, fields ...Field)
- func (l *Log) Enabled(lvl Level) bool
- func (l *Log) Error(args ...any)
- func (l *Log) ErrorContext(ctx context.Context, args ...any)
- func (l *Log) Errorf(template string, args ...any)
- func (l *Log) ErrorfContext(ctx context.Context, template string, args ...any)
- func (l *Log) Errorw(msg string, keysAndValues ...any)
- func (l *Log) ErrorwContext(ctx context.Context, msg string, keysAndValues ...any)
- func (l *Log) Errorx(msg string, fields ...Field)
- func (l *Log) ErrorxContext(ctx context.Context, msg string, fields ...Field)
- func (l *Log) Fatal(args ...any)
- func (l *Log) FatalContext(ctx context.Context, args ...any)
- func (l *Log) Fatalf(template string, args ...any)
- func (l *Log) FatalfContext(ctx context.Context, template string, args ...any)
- func (l *Log) Fatalw(msg string, keysAndValues ...any)
- func (l *Log) FatalwContext(ctx context.Context, msg string, keysAndValues ...any)
- func (l *Log) Fatalx(msg string, fields ...Field)
- func (l *Log) FatalxContext(ctx context.Context, msg string, fields ...Field)
- func (l *Log) GetLevel() Level
- func (l *Log) Info(args ...any)
- func (l *Log) InfoContext(ctx context.Context, args ...any)
- func (l *Log) Infof(template string, args ...any)
- func (l *Log) InfofContext(ctx context.Context, template string, args ...any)
- func (l *Log) Infow(msg string, keysAndValues ...any)
- func (l *Log) InfowContext(ctx context.Context, msg string, keysAndValues ...any)
- func (l *Log) Infox(msg string, fields ...Field)
- func (l *Log) InfoxContext(ctx context.Context, msg string, fields ...Field)
- func (l *Log) Log(ctx context.Context, level Level, args ...any)
- func (l *Log) Logf(ctx context.Context, level Level, template string, args ...any)
- func (l *Log) Logger() *zap.Logger
- func (l *Log) Logw(ctx context.Context, level Level, msg string, keysAndValues ...any)
- func (l *Log) Logx(ctx context.Context, level Level, msg string, fields ...Field)
- func (l *Log) Named(name string) *Log
- func (l *Log) Panic(args ...any)
- func (l *Log) PanicContext(ctx context.Context, args ...any)
- func (l *Log) Panicf(template string, args ...any)
- func (l *Log) PanicfContext(ctx context.Context, template string, args ...any)
- func (l *Log) Panicw(msg string, keysAndValues ...any)
- func (l *Log) PanicwContext(ctx context.Context, msg string, keysAndValues ...any)
- func (l *Log) Panicx(msg string, fields ...Field)
- func (l *Log) PanicxContext(ctx context.Context, msg string, fields ...Field)
- func (l *Log) SetCaller(f func(depth int, skipPackages ...string) Field) *Log
- func (l *Log) SetCallerLevel(lv Level) *Log
- func (l *Log) SetDefaultValuer(fs ...Valuer) *Log
- func (l *Log) SetLevel(lv Level) *Log
- func (l *Log) SetLevelWithText(text string) error
- func (l *Log) Sugar() *zap.SugaredLogger
- func (l *Log) Sync() error
- func (l *Log) UnderlyingCallerLevel() AtomicLevel
- func (l *Log) UseExternalCallerLevel(lvl AtomicLevel) *Log
- func (l *Log) V(lvl Level) bool
- func (l *Log) Warn(args ...any)
- func (l *Log) WarnContext(ctx context.Context, args ...any)
- func (l *Log) Warnf(template string, args ...any)
- func (l *Log) WarnfContext(ctx context.Context, template string, args ...any)
- func (l *Log) Warnw(msg string, keysAndValues ...any)
- func (l *Log) WarnwContext(ctx context.Context, msg string, keysAndValues ...any)
- func (l *Log) Warnx(msg string, fields ...Field)
- func (l *Log) WarnxContext(ctx context.Context, msg string, fields ...Field)
- func (l *Log) With(fields ...Field) *Log
- func (l *Log) WithNewValuer(fs ...Valuer) *Log
- func (l *Log) WithValuer(fs ...Valuer) *Log
- type LumberjackFile
- type ObjectMarshaler
- type Option
- func WithAdapter(adapter string, writer ...io.Writer) Option
- func WithConfig(cfg Config) Option
- func WithEnableCompress() Option
- func WithEnableLocalTime() Option
- func WithEncodeLevel(encodeLevel string) Option
- func WithEncoderConfig(encoderConfig *zapcore.EncoderConfig) Option
- func WithFilename(filename string) Option
- func WithFormat(format string) Option
- func WithLevel(level string) Option
- func WithMaxAge(maxAge int) Option
- func WithMaxBackups(maxBackups int) Option
- func WithMaxSize(maxSize int) Option
- func WithPath(path string) Option
- func WithStack(stack bool) Option
- type Valuer
- func App(v string) Valuer
- func Caller(depth int, skipPackages ...string) Valuer
- func Component(v string) Valuer
- func File(depth int, skipPackages ...string) Valuer
- func FromAny(key string, vf func(context.Context) any) Valuer
- func FromBinary(key string, vf func(context.Context) []byte) Valuer
- func FromBool(key string, vf func(context.Context) bool) Valuer
- func FromBoolp(key string, vf func(context.Context) *bool) Valuer
- func FromByteString(key string, vf func(context.Context) []byte) Valuer
- func FromComplex128(key string, vf func(context.Context) complex128) Valuer
- func FromComplex128p(key string, vf func(context.Context) *complex128) Valuer
- func FromComplex64(key string, vf func(context.Context) complex64) Valuer
- func FromComplex64p(key string, vf func(context.Context) *complex64) Valuer
- func FromDuration(key string, vf func(context.Context) time.Duration) Valuer
- func FromDurationp(key string, vf func(context.Context) *time.Duration) Valuer
- func FromErr(vf func(context.Context) error) Valuer
- func FromErrors(key string, vf func(context.Context) []error) Valuer
- func FromFloat32(key string, vf func(context.Context) float32) Valuer
- func FromFloat32p(key string, vf func(context.Context) *float32) Valuer
- func FromFloat64(key string, vf func(context.Context) float64) Valuer
- func FromFloat64p(key string, vf func(context.Context) *float64) Valuer
- func FromInt(key string, vf func(context.Context) int) Valuer
- func FromInt16(key string, vf func(context.Context) int16) Valuer
- func FromInt16p(key string, vf func(context.Context) *int16) Valuer
- func FromInt32(key string, vf func(context.Context) int32) Valuer
- func FromInt32p(key string, vf func(context.Context) *int32) Valuer
- func FromInt64(key string, vf func(context.Context) int64) Valuer
- func FromInt64p(key string, vf func(context.Context) *int64) Valuer
- func FromInt8(key string, vf func(context.Context) int8) Valuer
- func FromInt8p(key string, vf func(context.Context) *int8) Valuer
- func FromIntp(key string, vf func(context.Context) *int) Valuer
- func FromNamedError(key string, vf func(context.Context) error) Valuer
- func FromReflect(key string, vf func(context.Context) any) Valuer
- func FromString(key string, vf func(context.Context) string) Valuer
- func FromStringer(key string, vf func(context.Context) fmt.Stringer) Valuer
- func FromStringp(key string, vf func(context.Context) *string) Valuer
- func FromTime(key string, vf func(context.Context) time.Time) Valuer
- func FromTimep(key string, vf func(context.Context) *time.Time) Valuer
- func FromUint(key string, vf func(context.Context) uint) Valuer
- func FromUint16(key string, vf func(context.Context) uint16) Valuer
- func FromUint16p(key string, vf func(context.Context) *uint16) Valuer
- func FromUint32(key string, vf func(context.Context) uint32) Valuer
- func FromUint32p(key string, vf func(context.Context) *uint32) Valuer
- func FromUint64(key string, vf func(context.Context) uint64) Valuer
- func FromUint64p(key string, vf func(context.Context) *uint64) Valuer
- func FromUint8(key string, vf func(context.Context) uint8) Valuer
- func FromUint8p(key string, vf func(context.Context) *uint8) Valuer
- func FromUintp(key string, vf func(context.Context) *uint) Valuer
- func FromUintptr(key string, vf func(context.Context) uintptr) Valuer
- func FromUintptrp(key string, vf func(context.Context) *uintptr) Valuer
- func ImmutAny(key string, v any) Valuer
- func ImmutBinary(key string, v []byte) Valuer
- func ImmutBool(key string, v bool) Valuer
- func ImmutBoolp(key string, v *bool) Valuer
- func ImmutByteString(key string, v []byte) Valuer
- func ImmutComplex128(key string, v complex128) Valuer
- func ImmutComplex128p(key string, v *complex128) Valuer
- func ImmutComplex64(key string, v complex64) Valuer
- func ImmutComplex64p(key string, v *complex64) Valuer
- func ImmutDict(key string, val ...Field) Valuer
- func ImmutDuration(key string, v time.Duration) Valuer
- func ImmutDurationp(key string, v *time.Duration) Valuer
- func ImmutErr(val error) Valuer
- func ImmutErrors(key string, val []error) Valuer
- func ImmutFloat32(key string, v float32) Valuer
- func ImmutFloat32p(key string, v *float32) Valuer
- func ImmutFloat64(key string, v float64) Valuer
- func ImmutFloat64p(key string, v *float64) Valuer
- func ImmutInline(val ObjectMarshaler) Valuer
- func ImmutInt(key string, v int) Valuer
- func ImmutInt16(key string, v int16) Valuer
- func ImmutInt16p(key string, v *int16) Valuer
- func ImmutInt32(key string, v int32) Valuer
- func ImmutInt32p(key string, v *int32) Valuer
- func ImmutInt64(key string, v int64) Valuer
- func ImmutInt64p(key string, v *int64) Valuer
- func ImmutInt8(key string, v int8) Valuer
- func ImmutInt8p(key string, v *int8) Valuer
- func ImmutIntp(key string, v *int) Valuer
- func ImmutNamedError(key string, val error) Valuer
- func ImmutNamespace(key string) Valuer
- func ImmutObject(key string, val ObjectMarshaler) Valuer
- func ImmutReflect(key string, v any) Valuer
- func ImmutStack(key string) Valuer
- func ImmutStackSkip(key string, skip int) Valuer
- func ImmutString(key string, v string) Valuer
- func ImmutStringer(key string, v fmt.Stringer) Valuer
- func ImmutStringp(key string, v *string) Valuer
- func ImmutTime(key string, v time.Time) Valuer
- func ImmutTimep(key string, v *time.Time) Valuer
- func ImmutUint(key string, v uint) Valuer
- func ImmutUint16(key string, v uint16) Valuer
- func ImmutUint16p(key string, v *uint16) Valuer
- func ImmutUint32(key string, v uint32) Valuer
- func ImmutUint32p(key string, v *uint32) Valuer
- func ImmutUint64(key string, v uint64) Valuer
- func ImmutUint64p(key string, v *uint64) Valuer
- func ImmutUint8(key string, v uint8) Valuer
- func ImmutUint8p(key string, v *uint8) Valuer
- func ImmutUintp(key string, v *uint) Valuer
- func ImmutUintptr(key string, v uintptr) Valuer
- func ImmutUintptrp(key string, v *uintptr) Valuer
- func Kind(v string) Valuer
- func Module(v string) Valuer
- func Package(v string) Valuer
- func RequestId(f func(c context.Context) string) Valuer
- func Source(f func(c context.Context) string) Valuer
- func TraceId(f func(c context.Context) string) Valuer
- func Type(v string) Valuer
- func Unit(v string) Valuer
Constants ¶
const ( DebugLevel = zap.DebugLevel InfoLevel = zap.InfoLevel WarnLevel = zap.WarnLevel ErrorLevel = zap.ErrorLevel DPanicLevel = zap.DPanicLevel PanicLevel = zap.PanicLevel FatalLevel = zap.FatalLevel )
log level defined
const ( AdapterConsole = "console" // console AdapterFile = "file" // file AdapterMulti = "multi" // file and console AdapterCustom = "custom" // custom io.Writer AdapterConsoleCustom = "console-custom" // console and custom io.Writer AdapterFileCustom = "file-custom" // file and custom io.Writer AdapterMultiCustom = "multi-custom" // file, console and custom io.Writer )
adapter defined
const ( FormatJson = "json" FormatConsole = "console" )
format defined
const ( EncodeLevelLowercase = "LowercaseLevelEncoder" // 小写编码器 EncodeLevelLowercaseColor = "LowercaseColorLevelEncoder" // 小写编码器带颜色 EncodeLevelCapital = "CapitalLevelEncoder" // 大写编码器 EncodeLevelCapitalColor = "CapitalColorLevelEncoder" // 大写编码器带颜色 )
encode level defined
Variables ¶
This section is empty.
Functions ¶
func DPanicContext ¶
func DebugContext ¶
func ErrorContext ¶
func FatalContext ¶
func InfoContext ¶
func PanicContext ¶
func PoolGet ¶
func PoolGet() *fieldContainer
PoolGet selects an arbitrary item from the field Pool, removes it from the field Pool, and returns it to the caller. PoolGet may choose to ignore the field pool and treat it as empty. Callers should not assume any relation between values passed to PoolPut and the values returned by PoolGet.
NOTE: This function should be call PoolPut to give back. NOTE: You should know `sync.Pool` work principle ```go
fc := logger.PoolGet() defer logger.PoolPut(fc) fc.Fields = append(fc.Fields, logger.String("k1", "v1")) ... use fc.Fields
```
func ReplaceGlobals ¶
func ReplaceGlobals(logger *Log)
ReplaceGlobals replaces the global Log only once.
func SetLevelWithText ¶
SetLevelWithText alters the logging level. ParseAtomicLevel set the logging level based on a lowercase or all-caps ASCII representation of the log level. If the provided ASCII representation is invalid an error is returned.
func Sugar ¶
func Sugar() *zap.SugaredLogger
Sugar wraps the Logger to provide a more ergonomic, but slightly slower, API. Sugaring a Logger is quite inexpensive, so it's reasonable for a single application to use both Loggers and SugaredLoggers, converting between them on the boundaries of performance-sensitive code.
func WarnContext ¶
Types ¶
type AtomicLevel ¶
type AtomicLevel = zap.AtomicLevel
func NewAtomicLevel ¶
func NewAtomicLevel() AtomicLevel
NewAtomicLevel creates an AtomicLevel with InfoLevel and above logging enabled.
func NewAtomicLevelAt ¶
func NewAtomicLevelAt(l Level) AtomicLevel
NewAtomicLevelAt is a convenience function that creates an AtomicLevel and then calls SetLevel with the given level.
func ParseAtomicLevel ¶
func ParseAtomicLevel(text string) (AtomicLevel, error)
ParseAtomicLevel parses an AtomicLevel based on a lowercase or all-caps ASCII representation of the log level. If the provided ASCII representation is invalid an error is returned.
func UnderlyingCallerLevel ¶
func UnderlyingCallerLevel() AtomicLevel
UnderlyingCallerLevel get underlying caller level.
type CallerCore ¶
type CallerCore struct { Skip int SkipPackages []string Caller func(depth int, skipPackages ...string) Field // contains filtered or unexported fields }
func NewCallerCore ¶
func NewCallerCore() *CallerCore
func (*CallerCore) AddSkip ¶
func (c *CallerCore) AddSkip(callerSkip int) *CallerCore
AddSkip add the number of callers skipped by caller annotation.
func (*CallerCore) AddSkipPackage ¶
func (c *CallerCore) AddSkipPackage(vs ...string) *CallerCore
AddSkipPackage add the caller skip package.
func (*CallerCore) Enabled ¶
func (c *CallerCore) Enabled(lvl Level) bool
Enabled returns true if the given level is at or above this level.
func (*CallerCore) Level ¶
func (c *CallerCore) Level() Level
Level returns the minimum enabled log level.
func (*CallerCore) SetLevel ¶
func (c *CallerCore) SetLevel(lv Level) *CallerCore
SetLevel set the caller level.
func (*CallerCore) UnderlyingLevel ¶
func (c *CallerCore) UnderlyingLevel() AtomicLevel
UnderlyingLevel get underlying level.
func (*CallerCore) UseExternalLevel ¶
func (c *CallerCore) UseExternalLevel(l AtomicLevel) *CallerCore
UseExternalLevel use external level, which controller by user.
type Config ¶
type Config struct { // Level 日志等级, debug,info,warn,error,dpanic,panic,fatal, 默认warn Level string `yaml:"level" json:"level"` // Format: 编码格式: json,console 默认json Format string `yaml:"format" json:"format"` // 编码器类型, 默认: LowercaseLevelEncoder // LowercaseLevelEncoder: 小写编码器 // LowercaseColorLevelEncoder: 小写编码器带颜色 // CapitalLevelEncoder: 大写编码器 // CapitalColorLevelEncoder: 大写编码器带颜色 EncodeLevel string `yaml:"encodeLevel" json:"encodeLevel"` // Adapter 输出适配器, file,console,multi,custom,file-custom,console-custom,multi-custom 默认 console Adapter string `yaml:"adapter" json:"adapter"` // Stack 是否使能栈调试输出, 默认false Stack bool `yaml:"stack" json:"stack"` // Writer 输出 // 当adapter有附带custom时, 如果为writer为空, 将使用os.Stdout Writer []io.Writer `yaml:"-" json:"-"` // EncoderConfig 如果配置该项,则 EncodeLevel 将被覆盖 EncoderConfig *zapcore.EncoderConfig `yaml:"-" json:"-"` // 文件配置, 仅Adapter有file时有效 File LumberjackFile `yaml:"file" json:"file"` }
Config 日志配置
type Field ¶
func ByteString ¶
func Complex128 ¶
func Complex128(key string, val complex128) Field
func Complex128p ¶
func Complex128p(key string, val *complex128) Field
func Complex64p ¶
func DefaultCaller ¶
DefaultCaller caller.
func DefaultCallerFile ¶
DefaultCallerFile caller file.
func Inline ¶
func Inline(val ObjectMarshaler) Field
func NamedError ¶
func Object ¶
func Object(key string, val ObjectMarshaler) Field
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log wrap zap logger - methods named after the log level or ending in "Context" for log.Print-style logging - methods ending in "w" or "wContext" for loosely-typed structured logging - methods ending in "f" or "fContext" for log.Printf-style logging - methods ending in "x" or "xContext" for structured logging
func AddCallerSkip ¶
AddCallerSkip add the number of callers skipped by caller annotation.
func AddCallerSkipPackage ¶
AddCallerSkipPackage add the caller skip package.
func NewLogger ¶
NewLogger new logger 默认配置:
Level: 日志等级, 默认warn Format: 编码格式, 默认json EncodeLevel: 编码器类型, 默认LowercaseLevelEncoder Adapter: 默认输出适合器, 默认console` Stack: 是否使能栈调试输出, 默认false Path: 日志保存路径, 默认当前路径 Writer: 当adapter有附带custom时, 如果为writer为空, 将使用os.Stdout EncoderConfig: 如果配置该项,则 EncodeLevel 将被覆盖
文件日志切割配置(启用file时生效) Filename 空字符使用默认, 默认<processname>-lumberjack.log MaxSize 每个日志文件最大尺寸(MB), 默认100MB MaxAge 日志文件保存天数, 默认0 不删除 MaxBackups 日志文件保存备份数, 默认0 都保存 LocalTime 是否格式化时间戳, 默认UTC时间 Compress 是否使用gzip压缩文件, 采用默认不压缩
Caller相关 callerLevel caller日志级别, 默认warn callerSkip caller设置跳过深度, 默认0 callerSkipPackages caller设置跳过的包名, 默认空
func NewLoggerWith ¶
func NewLoggerWith(logger *zap.Logger, lv AtomicLevel) *Log
NewLoggerWith new logger with zap logger and atomic level
func SetDefaultValuer ¶
SetDefaultValuer set default field function, which hold always until you call XXXContext. suggest
func UseExternalCallerLevel ¶
func UseExternalCallerLevel(lvl AtomicLevel) *Log
UseExternalCallerLevel use external caller level, which controller by user.
func With ¶
With adds a variadic number of fields to the logging context. It accepts a mix of strongly-typed Field objects and loosely-typed key-value pairs. When processing pairs, the first element of the pair is used as the field key and the second as the field value.
For example,
sugaredLogger.With( "hello", "world", "failure", errors.New("oh no"), "count", 42, "user", User{Name: "alice"}, )
is the equivalent of
unsugared.With( String("hello", "world"), String("failure", "oh no"), Stack(), Int("count", 42), Object("user", User{Name: "alice"}), )
Note that the keys in key-value pairs should be strings. In development, passing a non-string key panics. In production, the logger is more forgiving: a separate error is logged, but the key-value pair is skipped and execution continues. Passing an orphaned key triggers similar behavior: panics in development and errors in production.
func WithNewValuer ¶
WithNewValuer return log with new Valuer function without default Valuer.
func (*Log) AddCallerSkip ¶
AddCallerSkip add the number of callers skipped by caller annotation.
func (*Log) AddCallerSkipPackage ¶
AddCallerSkipPackage add the caller skip package.
func (*Log) DPanicContext ¶
DPanicContext uses fmt.Sprint to construct and log a message. In development, the logger then panics. (see DPanicLevel for details.)
func (*Log) DPanicfContext ¶
DPanicfContext uses fmt.Sprintf to log a templated message. In development, the logger then panics. (see DPanicLevel for details.)
func (*Log) DPanicwContext ¶
DPanicwContext logs a message with some additional context. In development, the logger then panics. (see DPanicLevel for details.) The variadic key-value pairs or Field are treated as they are in With.
func (*Log) DPanicxContext ¶
DPanicContext uses fmt.Sprint to construct and log a message. In development, the logger then panics. (see DPanicLevel for details.)
func (*Log) DebugContext ¶
DebugContext uses fmt.Sprint to construct and log a message.
func (*Log) DebugfContext ¶
DebugfContext uses fmt.Sprintf to log a templated message.
func (*Log) DebugwContext ¶
DebugwContext logs a message with some additional context. The variadic key-value or Field pairs or Field are treated as they are in With.
When debug-level logging is disabled, this is much faster than
s.With(fields).Debug(msg)
func (*Log) DebugxContext ¶
DebugContext uses fmt.Sprint to construct and log a message.
func (*Log) ErrorContext ¶
ErrorContext uses fmt.Sprint to construct and log a message.
func (*Log) ErrorfContext ¶
ErrorfContext uses fmt.Sprintf to log a templated message.
func (*Log) ErrorwContext ¶
ErrorwContext logs a message with some additional context. The variadic key-value pairs or Field are treated as they are in With.
func (*Log) ErrorxContext ¶
ErrorContext uses fmt.Sprint to construct and log a message.
func (*Log) FatalContext ¶
FatalContext uses fmt.Sprint to construct and log a message, then calls os.Exit.
func (*Log) FatalfContext ¶
Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.
func (*Log) FatalwContext ¶
FatalwContext logs a message with some additional context, then calls os.Exit. The variadic key-value pairs or Field are treated as they are in With.
func (*Log) FatalxContext ¶
FatalContext uses fmt.Sprint to construct and log a message, then calls os.Exit.
func (*Log) InfoContext ¶
InfoContext uses fmt.Sprint to construct and log a message.
func (*Log) InfofContext ¶
InfofContext uses fmt.Sprintf to log a templated message.
func (*Log) InfowContext ¶
InfowContext logs a message with some additional context. The variadic key-value pairs or Field are treated as they are in With.
func (*Log) InfoxContext ¶
InfoContext uses fmt.Sprint to construct and log a message.
func (*Log) PanicContext ¶
PanicContext uses fmt.Sprint to to construct and log a message, then panics.
func (*Log) PanicfContext ¶
PanicfContext uses fmt.Sprintf to log a templated message, then panics.
func (*Log) PanicwContext ¶
PanicwContext logs a message with some additional context, then panics. The variadic key-value pairs or Field are treated as they are in With.
func (*Log) PanicxContext ¶
PanicContext uses fmt.Sprint to to construct and log a message, then panics.
func (*Log) SetCallerLevel ¶
SetCallerLevel set the caller level.
func (*Log) SetDefaultValuer ¶
SetDefaultValuer set default Valuer function, which hold always until you call XXXContext.
func (*Log) SetLevelWithText ¶
SetLevelWithText alters the logging level. ParseAtomicLevel set the logging level based on a lowercase or all-caps ASCII representation of the log level. If the provided ASCII representation is invalid an error is returned. see zapcore.Level
func (*Log) Sugar ¶
func (l *Log) Sugar() *zap.SugaredLogger
Sugar wraps the Logger to provide a more ergonomic, but slightly slower, API. Sugaring a Logger is quite inexpensive, so it's reasonable for a single application to use both Loggers and SugaredLoggers, converting between them on the boundaries of performance-sensitive code.
func (*Log) UnderlyingCallerLevel ¶
func (l *Log) UnderlyingCallerLevel() AtomicLevel
UnderlyingCallerLevel get underlying caller level.
func (*Log) UseExternalCallerLevel ¶
func (l *Log) UseExternalCallerLevel(lvl AtomicLevel) *Log
UseExternalCallerLevel use external caller level, which controller by user.
func (*Log) WarnContext ¶
WarnContext uses fmt.Sprint to construct and log a message.
func (*Log) WarnfContext ¶
WarnfContext uses fmt.Sprintf to log a templated message.
func (*Log) WarnwContext ¶
WarnwContext logs a message with some additional context. The variadic key-value pairs or Field are treated as they are in With.
func (*Log) WarnxContext ¶
WarnContext uses fmt.Sprint to construct and log a message.
func (*Log) With ¶
With creates a child logger and adds structured context to it. Fields added to the child don't affect the parent, and vice versa.
func (*Log) WithNewValuer ¶
WithNewValuer return log with new Valuer function without default Valuer.
func (*Log) WithValuer ¶
WithValuer with Valuer function.
type LumberjackFile ¶ added in v0.2.0
type LumberjackFile struct { // Path 日志保存路径, 默认 empty, 即当前路径 Path string `yaml:"path" json:"path"` // see https://github.com/natefinch/lumberjack // lumberjack.Log // Filename 空字符使用默认, 默认<processname>-lumberjack.log Filename string `yaml:"filename" json:"filename"` // MaxSize 每个日志文件最大尺寸(MB), 默认100MB MaxSize int `yaml:"maxSize" json:"maxSize"` // MaxAge 日志文件保存天数, 默认0 不删除 MaxAge int `yaml:"maxAge" json:"maxAge"` // MaxBackups 日志文件保存备份数, 默认0 都保存 MaxBackups int `yaml:"maxBackups" json:"maxBackups"` // LocalTime 是否格式化时间戳, 默认UTC时间 LocalTime bool `yaml:"localTime" json:"localTime"` // Compress 是否使用gzip压缩文件, 采用默认不压缩 Compress bool `yaml:"compress" json:"compress"` }
type ObjectMarshaler ¶
type ObjectMarshaler = zapcore.ObjectMarshaler
type Option ¶
type Option func(c *Config)
Option An Option configures a Log.
func WithAdapter ¶
WithAdapter with adapter file,console(default),multi,custom,file-custom,console-custom,multi-custom writer: 当 adapter=custom 使用,如果为writer为空,将使用os.Stdout
func WithEnableCompress ¶
func WithEnableCompress() Option
WithEnableCompress with compress 是否使用gzip压缩文件, 采用默认不压缩
func WithEnableLocalTime ¶
func WithEnableLocalTime() Option
WithEnableLocalTime with local time 是否格式化时间戳, 默认UTC时间
func WithEncodeLevel ¶
WithEncodeLevel with EncodeLevel LowercaseLevelEncoder(default): 小写编码器 LowercaseColorLevelEncoder: 小写编码器带颜色 CapitalLevelEncoder: 大写编码器 CapitalColorLevelEncoder: 大写编码器带颜色
func WithEncoderConfig ¶
func WithEncoderConfig(encoderConfig *zapcore.EncoderConfig) Option
EncoderConfig 如果配置该项,则 EncodeLevel 将被覆盖
func WithFilename ¶
WithFilename with filename 空字符使用默认, 默认<processname>-lumberjack.log
func WithFormat ¶
WithFormat with format json(default) or console
func WithMaxBackups ¶
WithMaxBackups with max backup 日志文件保存备份数, 默认0 都保存
func WithMaxSize ¶
WithMaxSize with max size 每个日志文件最大尺寸(MB), 默认100MB
type Valuer ¶
Valuer is returns a log value.
func FromComplex128 ¶
func FromComplex128(key string, vf func(context.Context) complex128) Valuer
func FromComplex128p ¶
func FromComplex128p(key string, vf func(context.Context) *complex128) Valuer
func ImmutBinary ¶
func ImmutBoolp ¶
func ImmutByteString ¶
func ImmutComplex128 ¶
func ImmutComplex128(key string, v complex128) Valuer
func ImmutComplex128p ¶
func ImmutComplex128p(key string, v *complex128) Valuer
func ImmutComplex64 ¶
func ImmutComplex64p ¶
func ImmutErrors ¶
func ImmutFloat32 ¶
func ImmutFloat32p ¶
func ImmutFloat64 ¶
func ImmutFloat64p ¶
func ImmutInline ¶
func ImmutInline(val ObjectMarshaler) Valuer
func ImmutInt16 ¶
func ImmutInt16p ¶
func ImmutInt32 ¶
func ImmutInt32p ¶
func ImmutInt64 ¶
func ImmutInt64p ¶
func ImmutInt8p ¶
func ImmutNamedError ¶
func ImmutNamespace ¶
func ImmutObject ¶
func ImmutObject(key string, val ObjectMarshaler) Valuer