Documentation ¶
Index ¶
- Variables
- func Debug(msg string, fields ...zap.Field)
- func DefaultTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func Error(msg string, fields ...zap.Field)
- func Fatal(msg string, fields ...zap.Field)
- func GetLevel() zapcore.Level
- func Info(msg string, fields ...zap.Field)
- func L() *zap.Logger
- func Level() zap.AtomicLevel
- func NewEncoderConfig() *zapcore.EncoderConfig
- func NewTextCore(enc zapcore.Encoder, ws zapcore.WriteSyncer, enab zapcore.LevelEnabler) zapcore.Core
- func NewTextEncoder(encoderConfig *zapcore.EncoderConfig, spaced bool, disableErrorVerbose bool) zapcore.Encoder
- func NewTextEncoderByConfig(cfg *Config) zapcore.Encoder
- func Panic(msg string, fields ...zap.Field)
- func ReplaceGlobals(logger *zap.Logger, props *ZapProperties)
- func S() *zap.SugaredLogger
- func SetLevel(l zapcore.Level)
- func Setup(level, logFile string, handlers ...zapcore.Core)
- func SetupLogger(cfg *Config)
- func ShortCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
- func Sync() error
- func Type(key string, v interface{}) zap.Field
- func Warn(msg string, fields ...zap.Field)
- func WithDebugLevel(ctx context.Context) context.Context
- func WithErrorLevel(ctx context.Context) context.Context
- func WithFatalLevel(ctx context.Context) context.Context
- func WithFields(ctx context.Context, fields ...zap.Field) context.Context
- func WithInfoLevel(ctx context.Context) context.Context
- func WithModule(ctx context.Context, module string) context.Context
- func WithReqID(ctx context.Context, reqID int64) context.Context
- func WithTraceID(ctx context.Context, traceID string) context.Context
- func WithWarnLevel(ctx context.Context) context.Context
- type Config
- type FileLogConfig
- type MLogger
- type TextEncoder
- func (enc *TextEncoder) AddArray(key string, arr zapcore.ArrayMarshaler) error
- func (enc *TextEncoder) AddBinary(key string, val []byte)
- func (enc *TextEncoder) AddBool(key string, val bool)
- func (enc *TextEncoder) AddByteString(key string, val []byte)
- func (enc *TextEncoder) AddComplex128(key string, val complex128)
- func (enc *TextEncoder) AddComplex64(k string, v complex64)
- func (enc *TextEncoder) AddDuration(key string, val time.Duration)
- func (enc *TextEncoder) AddFloat32(k string, v float32)
- func (enc *TextEncoder) AddFloat64(key string, val float64)
- func (enc *TextEncoder) AddInt(k string, v int)
- func (enc *TextEncoder) AddInt16(k string, v int16)
- func (enc *TextEncoder) AddInt32(k string, v int32)
- func (enc *TextEncoder) AddInt64(key string, val int64)
- func (enc *TextEncoder) AddInt8(k string, v int8)
- func (enc *TextEncoder) AddObject(key string, obj zapcore.ObjectMarshaler) error
- func (enc *TextEncoder) AddReflected(key string, obj interface{}) error
- func (enc *TextEncoder) AddString(key, val string)
- func (enc *TextEncoder) AddTime(key string, val time.Time)
- func (enc *TextEncoder) AddUint(k string, v uint)
- func (enc *TextEncoder) AddUint16(k string, v uint16)
- func (enc *TextEncoder) AddUint32(k string, v uint32)
- func (enc *TextEncoder) AddUint64(key string, val uint64)
- func (enc *TextEncoder) AddUint8(k string, v uint8)
- func (enc *TextEncoder) AddUintptr(k string, v uintptr)
- func (enc *TextEncoder) AppendArray(arr zapcore.ArrayMarshaler) error
- func (enc *TextEncoder) AppendBool(val bool)
- func (enc *TextEncoder) AppendByteString(val []byte)
- func (enc *TextEncoder) AppendComplex128(val complex128)
- func (enc *TextEncoder) AppendComplex64(v complex64)
- func (enc *TextEncoder) AppendDuration(val time.Duration)
- func (enc *TextEncoder) AppendFloat32(v float32)
- func (enc *TextEncoder) AppendFloat64(v float64)
- func (enc *TextEncoder) AppendInt(v int)
- func (enc *TextEncoder) AppendInt16(v int16)
- func (enc *TextEncoder) AppendInt32(v int32)
- func (enc *TextEncoder) AppendInt64(val int64)
- func (enc *TextEncoder) AppendInt8(v int8)
- func (enc *TextEncoder) AppendObject(obj zapcore.ObjectMarshaler) error
- func (enc *TextEncoder) AppendReflected(val interface{}) error
- func (enc *TextEncoder) AppendString(val string)
- func (enc *TextEncoder) AppendTime(val time.Time)
- func (enc *TextEncoder) AppendUint(v uint)
- func (enc *TextEncoder) AppendUint16(v uint16)
- func (enc *TextEncoder) AppendUint32(v uint32)
- func (enc *TextEncoder) AppendUint64(val uint64)
- func (enc *TextEncoder) AppendUint8(v uint8)
- func (enc *TextEncoder) AppendUintptr(v uintptr)
- func (enc *TextEncoder) Clone() zapcore.Encoder
- func (enc *TextEncoder) EncodeEntry(ent zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)
- func (enc *TextEncoder) OpenNamespace(key string)
- func (enc *TextEncoder) Reset()
- type ZapProperties
Constants ¶
This section is empty.
Variables ¶
var CtxLogKey = ctxLogKeyType{}
var (
// Get retrieves a buffer from the pool, creating one if necessary.
Get = _pool.Get
)
Functions ¶
func Debug ¶
Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func DefaultTimeEncoder ¶
func DefaultTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
DefaultTimeEncoder serializes time.Time to a human-readable formatted string
func Error ¶
Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func Fatal ¶
Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.
func Info ¶
Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func L ¶
L returns the global Logger, which can be reconfigured with ReplaceGlobals. It's safe for concurrent use.
func Level ¶
func Level() zap.AtomicLevel
func NewEncoderConfig ¶ added in v0.2.1
func NewEncoderConfig() *zapcore.EncoderConfig
func NewTextCore ¶
func NewTextCore(enc zapcore.Encoder, ws zapcore.WriteSyncer, enab zapcore.LevelEnabler) zapcore.Core
NewTextCore creates a Core that writes logs to a WriteSyncer.
func NewTextEncoder ¶
func NewTextEncoderByConfig ¶
NewTextEncoderByConfig creates a fast, low-allocation Text encoder with config. The encoder appropriately escapes all field keys and values.
func Panic ¶
Panic logs a message at PanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then panics, even if logging at PanicLevel is disabled.
func ReplaceGlobals ¶
func ReplaceGlobals(logger *zap.Logger, props *ZapProperties)
ReplaceGlobals replaces the global Logger and SugaredLogger. It's safe for concurrent use.
func S ¶
func S() *zap.SugaredLogger
S returns the global SugaredLogger, which can be reconfigured with ReplaceGlobals. It's safe for concurrent use.
func SetupLogger ¶
func SetupLogger(cfg *Config)
SetupLogger is used to initialize the log with config.
func ShortCallerEncoder ¶
func ShortCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
ShortCallerEncoder serializes a caller in file:line format.
func Warn ¶
Warn logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func WithDebugLevel ¶
WithDebugLevel returns context with a debug level enabled logger. Notes that it will overwrite previous attached logger within context
func WithErrorLevel ¶
WithErrorLevel returns context with a error level enabled logger. Notes that it will overwrite previous attached logger within context
func WithFatalLevel ¶
WithFatalLevel returns context with a fatal level enabled logger. Notes that it will overwrite previous attached logger within context
func WithFields ¶
WithFields returns a context with fields attached
func WithInfoLevel ¶
WithInfoLevel returns context with a info level enabled logger. Notes that it will overwrite previous attached logger within context
func WithModule ¶
WithModule adds given module field to the logger in ctx
func WithTraceID ¶
WithTraceID returns a context with trace_id attached
Types ¶
type Config ¶
type Config struct { // Log level. Level string `toml:"level" json:"level"` // Log format. one of json, text, or console. Format string `toml:"format" json:"format"` // Disable automatic timestamps in output. DisableTimestamp bool `toml:"disable-timestamp" json:"disable-timestamp"` // Stdout enable or not. Stdout bool `toml:"stdout" json:"stdout"` // File log config. File *FileLogConfig `toml:"file" json:"file"` // Development puts the logger in development mode, which changes the // behavior of DPanicLevel and takes stacktraces more liberally. Development bool `toml:"development" json:"development"` // DisableCaller stops annotating logs with the calling function's file // name and line number. By default, all logs are annotated. DisableCaller bool `toml:"disable-caller" json:"disable-caller"` // DisableStacktrace completely disables automatic stacktrace capturing. By // default, stacktraces are captured for WarnLevel and above logs in // development and ErrorLevel and above in production. DisableStacktrace bool `toml:"disable-stacktrace" json:"disable-stacktrace"` // DisableErrorVerbose stops annotating logs with the full verbose error // message. DisableErrorVerbose bool `toml:"disable-error-verbose" json:"disable-error-verbose"` // SamplingConfig sets a sampling strategy for the logger. Sampling caps the // global CPU and I/O load that logging puts on your process while attempting // to preserve a representative subset of your logs. // // Values configured here are per-second. See zapcore.NewSampler for details. Sampling *zap.SamplingConfig `toml:"sampling" json:"sampling"` // custom log handlers Handlers []zapcore.Core }
Config serializes log related config in toml/json.
type FileLogConfig ¶
type FileLogConfig struct { // Log logpath LogPath string `toml:"logpath" json:"logpath"` // Max size for a single file, in MB. MaxSize int `toml:"max-size" json:"max-size"` // Max log keep days, default is never deleting. MaxDays int `toml:"max-days" json:"max-days"` // Maximum number of old log files to retain. MaxBackups int `toml:"max-backups" json:"max-backups"` }
FileLogConfig serializes file log related config in toml/json.
type MLogger ¶
MLogger is a wrapper type of zap.Logger.
type TextEncoder ¶ added in v0.2.1
type TextEncoder struct { *zapcore.EncoderConfig Buf *buffer.Buffer // contains filtered or unexported fields }
func (*TextEncoder) AddArray ¶ added in v0.2.1
func (enc *TextEncoder) AddArray(key string, arr zapcore.ArrayMarshaler) error
func (*TextEncoder) AddBinary ¶ added in v0.2.1
func (enc *TextEncoder) AddBinary(key string, val []byte)
func (*TextEncoder) AddBool ¶ added in v0.2.1
func (enc *TextEncoder) AddBool(key string, val bool)
func (*TextEncoder) AddByteString ¶ added in v0.2.1
func (enc *TextEncoder) AddByteString(key string, val []byte)
func (*TextEncoder) AddComplex128 ¶ added in v0.2.1
func (enc *TextEncoder) AddComplex128(key string, val complex128)
func (*TextEncoder) AddComplex64 ¶ added in v0.2.1
func (enc *TextEncoder) AddComplex64(k string, v complex64)
func (*TextEncoder) AddDuration ¶ added in v0.2.1
func (enc *TextEncoder) AddDuration(key string, val time.Duration)
func (*TextEncoder) AddFloat32 ¶ added in v0.2.1
func (enc *TextEncoder) AddFloat32(k string, v float32)
func (*TextEncoder) AddFloat64 ¶ added in v0.2.1
func (enc *TextEncoder) AddFloat64(key string, val float64)
func (*TextEncoder) AddInt ¶ added in v0.2.1
func (enc *TextEncoder) AddInt(k string, v int)
func (*TextEncoder) AddInt16 ¶ added in v0.2.1
func (enc *TextEncoder) AddInt16(k string, v int16)
func (*TextEncoder) AddInt32 ¶ added in v0.2.1
func (enc *TextEncoder) AddInt32(k string, v int32)
func (*TextEncoder) AddInt64 ¶ added in v0.2.1
func (enc *TextEncoder) AddInt64(key string, val int64)
func (*TextEncoder) AddInt8 ¶ added in v0.2.1
func (enc *TextEncoder) AddInt8(k string, v int8)
func (*TextEncoder) AddObject ¶ added in v0.2.1
func (enc *TextEncoder) AddObject(key string, obj zapcore.ObjectMarshaler) error
func (*TextEncoder) AddReflected ¶ added in v0.2.1
func (enc *TextEncoder) AddReflected(key string, obj interface{}) error
func (*TextEncoder) AddString ¶ added in v0.2.1
func (enc *TextEncoder) AddString(key, val string)
func (*TextEncoder) AddTime ¶ added in v0.2.1
func (enc *TextEncoder) AddTime(key string, val time.Time)
func (*TextEncoder) AddUint ¶ added in v0.2.1
func (enc *TextEncoder) AddUint(k string, v uint)
func (*TextEncoder) AddUint16 ¶ added in v0.2.1
func (enc *TextEncoder) AddUint16(k string, v uint16)
func (*TextEncoder) AddUint32 ¶ added in v0.2.1
func (enc *TextEncoder) AddUint32(k string, v uint32)
func (*TextEncoder) AddUint64 ¶ added in v0.2.1
func (enc *TextEncoder) AddUint64(key string, val uint64)
func (*TextEncoder) AddUint8 ¶ added in v0.2.1
func (enc *TextEncoder) AddUint8(k string, v uint8)
func (*TextEncoder) AddUintptr ¶ added in v0.2.1
func (enc *TextEncoder) AddUintptr(k string, v uintptr)
func (*TextEncoder) AppendArray ¶ added in v0.2.1
func (enc *TextEncoder) AppendArray(arr zapcore.ArrayMarshaler) error
func (*TextEncoder) AppendBool ¶ added in v0.2.1
func (enc *TextEncoder) AppendBool(val bool)
func (*TextEncoder) AppendByteString ¶ added in v0.2.1
func (enc *TextEncoder) AppendByteString(val []byte)
func (*TextEncoder) AppendComplex128 ¶ added in v0.2.1
func (enc *TextEncoder) AppendComplex128(val complex128)
func (*TextEncoder) AppendComplex64 ¶ added in v0.2.1
func (enc *TextEncoder) AppendComplex64(v complex64)
func (*TextEncoder) AppendDuration ¶ added in v0.2.1
func (enc *TextEncoder) AppendDuration(val time.Duration)
func (*TextEncoder) AppendFloat32 ¶ added in v0.2.1
func (enc *TextEncoder) AppendFloat32(v float32)
func (*TextEncoder) AppendFloat64 ¶ added in v0.2.1
func (enc *TextEncoder) AppendFloat64(v float64)
func (*TextEncoder) AppendInt ¶ added in v0.2.1
func (enc *TextEncoder) AppendInt(v int)
func (*TextEncoder) AppendInt16 ¶ added in v0.2.1
func (enc *TextEncoder) AppendInt16(v int16)
func (*TextEncoder) AppendInt32 ¶ added in v0.2.1
func (enc *TextEncoder) AppendInt32(v int32)
func (*TextEncoder) AppendInt64 ¶ added in v0.2.1
func (enc *TextEncoder) AppendInt64(val int64)
func (*TextEncoder) AppendInt8 ¶ added in v0.2.1
func (enc *TextEncoder) AppendInt8(v int8)
func (*TextEncoder) AppendObject ¶ added in v0.2.1
func (enc *TextEncoder) AppendObject(obj zapcore.ObjectMarshaler) error
func (*TextEncoder) AppendReflected ¶ added in v0.2.1
func (enc *TextEncoder) AppendReflected(val interface{}) error
func (*TextEncoder) AppendString ¶ added in v0.2.1
func (enc *TextEncoder) AppendString(val string)
func (*TextEncoder) AppendTime ¶ added in v0.2.1
func (enc *TextEncoder) AppendTime(val time.Time)
func (*TextEncoder) AppendUint ¶ added in v0.2.1
func (enc *TextEncoder) AppendUint(v uint)
func (*TextEncoder) AppendUint16 ¶ added in v0.2.1
func (enc *TextEncoder) AppendUint16(v uint16)
func (*TextEncoder) AppendUint32 ¶ added in v0.2.1
func (enc *TextEncoder) AppendUint32(v uint32)
func (*TextEncoder) AppendUint64 ¶ added in v0.2.1
func (enc *TextEncoder) AppendUint64(val uint64)
func (*TextEncoder) AppendUint8 ¶ added in v0.2.1
func (enc *TextEncoder) AppendUint8(v uint8)
func (*TextEncoder) AppendUintptr ¶ added in v0.2.1
func (enc *TextEncoder) AppendUintptr(v uintptr)
func (*TextEncoder) Clone ¶ added in v0.2.1
func (enc *TextEncoder) Clone() zapcore.Encoder
func (*TextEncoder) EncodeEntry ¶ added in v0.2.1
func (*TextEncoder) OpenNamespace ¶ added in v0.2.1
func (enc *TextEncoder) OpenNamespace(key string)
func (*TextEncoder) Reset ¶ added in v0.2.1
func (enc *TextEncoder) Reset()
type ZapProperties ¶
type ZapProperties struct { Core zapcore.Core Syncer zapcore.WriteSyncer Level zap.AtomicLevel }
ZapProperties records some information about zap.
func InitLogger ¶
InitLogger initializes a zap logger.
func InitLoggerWithWriteSyncer ¶
func InitLoggerWithWriteSyncer(cfg *Config, output zapcore.WriteSyncer, handlers []zapcore.Core, opts ...zap.Option) (*zap.Logger, *ZapProperties, error)
InitLoggerWithWriteSyncer initializes a zap logger with specified write syncer.