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 New(opts ...Option) (*zap.Logger, zap.AtomicLevel)
- 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 ReplaceGlobals(logger *Log)
- func SetLevelWithText(text string) error
- func Sugar() *zap.SugaredLogger
- func Sync() error
- func V(lvl int) 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 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 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 Named(name string) *Log
- func NewLogger(opts ...Option) *Log
- func NewLoggerWith(logger *zap.Logger, lv zap.AtomicLevel) *Log
- func SetDefaultValuer(vs ...Valuer) *Log
- func SetLevel(lv zapcore.Level) *Log
- func With(fields ...Field) *Log
- func WithContext(ctx context.Context) *Logdeprecated
- func WithNewValuer(fs ...Valuer) *Log
- func WithValuer(vs ...Valuer) *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) SetDefaultValuer(fs ...Valuer) *Log
- func (l *Log) SetLevel(lv zapcore.Level) *Log
- func (l *Log) SetLevelWithText(text string) error
- func (l *Log) Sugar() *zap.SugaredLogger
- func (l *Log) Sync() error
- func (l *Log) V(lvl int) 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) WithContext(ctx context.Context) *Logdeprecated
- func (l *Log) WithNewValuer(fs ...Valuer) *Log
- func (l *Log) WithValuer(fs ...Valuer) *Log
- type ObjectMarshaler
- type Option
- func WithAdapter(adapter string, writer ...io.Writer) Option
- func WithAddCaller(b bool) Option
- func WithCallerSkip(skip int) 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) Valuer
- func Component(v string) Valuer
- func File(depth int) 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 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 )
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
Variables ¶
This section is empty.
Functions ¶
func DPanicContext ¶ added in v0.0.4
func DPanicfContext ¶ added in v0.0.4
func DPanicwContext ¶ added in v0.0.4
func DPanicxContext ¶ added in v0.0.4
func DebugContext ¶ added in v0.0.4
func DebugfContext ¶ added in v0.0.4
func DebugwContext ¶ added in v0.0.4
func DebugxContext ¶ added in v0.0.4
func ErrorContext ¶ added in v0.0.4
func ErrorfContext ¶ added in v0.0.4
func ErrorwContext ¶ added in v0.0.4
func ErrorxContext ¶ added in v0.0.4
func FatalContext ¶ added in v0.0.4
func FatalfContext ¶ added in v0.0.4
func FatalwContext ¶ added in v0.0.4
func FatalxContext ¶ added in v0.0.4
func InfoContext ¶ added in v0.0.4
func InfofContext ¶ added in v0.0.4
func InfowContext ¶ added in v0.0.4
func InfoxContext ¶ added in v0.0.4
func PanicContext ¶ added in v0.0.4
func PanicfContext ¶ added in v0.0.4
func PanicwContext ¶ added in v0.0.4
func PanicxContext ¶ added in v0.0.4
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 ¶ added in v0.0.4
func WarnfContext ¶ added in v0.0.4
func WarnwContext ¶ added in v0.0.4
Types ¶
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"` // AddCaller add caller AddCaller bool `yaml:"addCaller" json:"addCaller"` // CallerSkip call skip if AddCaller enabled CallerSkip int `yaml:"callerSkip" json:"callerSkip"` // Path 日志保存路径, 默认 empty, 即当前路径 Path string `yaml:"path" json:"path"` // Writer 输出 // 当 adapter=custom使用,如果为writer为空,将使用os.Stdout Writer []io.Writer `yaml:"-" json:"-"` // EncoderConfig 如果配置该项,则 EncodeLevel 将被覆盖 EncoderConfig *zapcore.EncoderConfig `yaml:"-" json:"-"` // 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"` }
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 Inline ¶ added in v0.0.4
func Inline(val ObjectMarshaler) Field
func NamedError ¶ added in v0.0.4
func Object ¶ added in v0.0.4
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 NewLoggerWith ¶
func NewLoggerWith(logger *zap.Logger, lv zap.AtomicLevel) *Log
NewLoggerWith new logger with zap logger and atomic level
func SetDefaultValuer ¶
SetDefaultValuer set default field function, which hold always until you call WithContext. suggest
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 WithContext
deprecated
func WithNewValuer ¶
WithNewValuer return log with new Valuer function without default Valuer.
func (*Log) DPanicContext ¶ added in v0.0.4
DPanicContext uses fmt.Sprint to construct and log a message. In development, the logger then panics. (see DPanicLevel for details.)
func (*Log) DPanicfContext ¶ added in v0.0.4
DPanicfContext uses fmt.Sprintf to log a templated message. In development, the logger then panics. (see DPanicLevel for details.)
func (*Log) DPanicwContext ¶ added in v0.0.4
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 ¶ added in v0.0.4
DPanicContext uses fmt.Sprint to construct and log a message. In development, the logger then panics. (see DPanicLevel for details.)
func (*Log) DebugContext ¶ added in v0.0.4
DebugContext uses fmt.Sprint to construct and log a message.
func (*Log) DebugfContext ¶ added in v0.0.4
DebugfContext uses fmt.Sprintf to log a templated message.
func (*Log) DebugwContext ¶ added in v0.0.4
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 ¶ added in v0.0.4
DebugContext uses fmt.Sprint to construct and log a message.
func (*Log) ErrorContext ¶ added in v0.0.4
ErrorContext uses fmt.Sprint to construct and log a message.
func (*Log) ErrorfContext ¶ added in v0.0.4
ErrorfContext uses fmt.Sprintf to log a templated message.
func (*Log) ErrorwContext ¶ added in v0.0.4
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 ¶ added in v0.0.4
ErrorContext uses fmt.Sprint to construct and log a message.
func (*Log) FatalContext ¶ added in v0.0.4
FatalContext uses fmt.Sprint to construct and log a message, then calls os.Exit.
func (*Log) FatalfContext ¶ added in v0.0.4
Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.
func (*Log) FatalwContext ¶ added in v0.0.4
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 ¶ added in v0.0.4
FatalContext uses fmt.Sprint to construct and log a message, then calls os.Exit.
func (*Log) InfoContext ¶ added in v0.0.4
InfoContext uses fmt.Sprint to construct and log a message.
func (*Log) InfofContext ¶ added in v0.0.4
InfofContext uses fmt.Sprintf to log a templated message.
func (*Log) InfowContext ¶ added in v0.0.4
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 ¶ added in v0.0.4
InfoContext uses fmt.Sprint to construct and log a message.
func (*Log) PanicContext ¶ added in v0.0.4
PanicContext uses fmt.Sprint to to construct and log a message, then panics.
func (*Log) PanicfContext ¶ added in v0.0.4
PanicfContext uses fmt.Sprintf to log a templated message, then panics.
func (*Log) PanicwContext ¶ added in v0.0.4
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 ¶ added in v0.0.4
PanicContext uses fmt.Sprint to to construct and log a message, then panics.
func (*Log) SetDefaultValuer ¶
SetDefaultValuer set default Valuer function, which hold always until you call WithContext.
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) WarnContext ¶ added in v0.0.4
WarnContext uses fmt.Sprint to construct and log a message.
func (*Log) WarnfContext ¶ added in v0.0.4
WarnfContext uses fmt.Sprintf to log a templated message.
func (*Log) WarnwContext ¶ added in v0.0.4
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 ¶ added in v0.0.4
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) WithContext
deprecated
func (*Log) WithNewValuer ¶
WithNewValuer return log with new Valuer function without default Valuer.
func (*Log) WithValuer ¶
WithValuer with Valuer function.
type ObjectMarshaler ¶ added in v0.0.4
type ObjectMarshaler = zapcore.ObjectMarshaler
type Option ¶
type Option func(c *Config)
Option An Option configures a Log.
func WithAdapter ¶
WithAdapter with adapter file,console,multi,custom,file-custom,console-custom,multi-custom writer: 当 adapter=custom使用,如果为writer为空,将使用os.Stdout 默认 console
func WithAddCaller ¶
WithAddCaller with AddCaller 是否输出调用 filename 和 line number
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: 小写编码器 LowercaseColorLevelEncoder: 小写编码器带颜色 CapitalLevelEncoder: 大写编码器 CapitalColorLevelEncoder: 大写编码器带颜色 默认: LowercaseLevelEncoder
func WithEncoderConfig ¶
func WithEncoderConfig(encoderConfig *zapcore.EncoderConfig) Option
EncoderConfig 如果配置该项,则 EncodeLevel 将被覆盖
func WithFilename ¶
WithFilename with filename 空字符使用默认, 默认<processname>-lumberjack.log
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 FromErrors ¶ added in v0.0.5
func FromNamedError ¶ added in v0.0.5
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 ¶ added in v0.0.4
func ImmutFloat32 ¶
func ImmutFloat32p ¶
func ImmutFloat64 ¶
func ImmutFloat64p ¶
func ImmutInline ¶ added in v0.0.4
func ImmutInline(val ObjectMarshaler) Valuer
func ImmutInt16 ¶
func ImmutInt16p ¶
func ImmutInt32 ¶
func ImmutInt32p ¶
func ImmutInt64 ¶
func ImmutInt64p ¶
func ImmutInt8p ¶
func ImmutNamedError ¶ added in v0.0.4
func ImmutNamespace ¶ added in v0.0.5
func ImmutObject ¶ added in v0.0.4
func ImmutObject(key string, val ObjectMarshaler) Valuer