Documentation
¶
Index ¶
- Constants
- func Check(lvl zapcore.Level, args ...any) *zapcore.CheckedEntry
- func Context(ctx context.Context) zapcore.Field
- func Debug(args ...any)
- func Debugf(template string, args ...any)
- func Debugw(msg string, fields ...zap.Field)
- func DefaultReflectedEncoder(w io.Writer) zapcore.ReflectedEncoder
- func Error(args ...any)
- func Errorf(template string, args ...any)
- func Errorw(msg string, fields ...zap.Field)
- func Fatal(args ...any)
- func Fatalf(template string, args ...any)
- func Fatalw(msg string, fields ...zap.Field)
- func FileWithLineNum() string
- func Info(args ...any)
- func Infof(template string, args ...any)
- func Infow(msg string, fields ...zap.Field)
- func Log(lvl zapcore.Level, args ...any)
- func Logf(lvl zapcore.Level, msg string, args ...any)
- func Logw(lvl zapcore.Level, msg string, fields ...zapcore.Field)
- func NewDevelopmentEncoderConfig() zapcore.EncoderConfig
- func NewProductionEncoderConfig() zapcore.EncoderConfig
- func Panic(args ...any)
- func Panicf(template string, args ...any)
- func Panicw(msg string, fields ...zap.Field)
- func Printf(template string, args ...any)
- func Println(args ...any)
- func RawJson(key string, data []byte) zapcore.Field
- func SetDefaultLogger(logger *Logger)
- func Sync() error
- func TrimLineBreak(path string) string
- func ValueLevelNotify[T constraintsx.Number](msg string, v, std T)
- func ValueRangeNotify[T cmp.Ordered](msg string, v, rangeMin, rangeMax T)
- func Warn(args ...any)
- func Warnf(template string, args ...any)
- func Warnw(msg string, fields ...zap.Field)
- type Config
- type CustomEncoder
- func (enc *CustomEncoder) AddArray(key string, arr zapcore.ArrayMarshaler) error
- func (enc *CustomEncoder) AddBinary(key string, val []byte)
- func (enc *CustomEncoder) AddBool(key string, val bool)
- func (enc *CustomEncoder) AddByteString(key string, val []byte)
- func (enc *CustomEncoder) AddComplex64(key string, val complex64)
- func (enc *CustomEncoder) AddComplex128(key string, val complex128)
- func (enc *CustomEncoder) AddDuration(key string, val time.Duration)
- func (enc *CustomEncoder) AddFloat32(key string, val float32)
- func (enc *CustomEncoder) AddFloat64(key string, val float64)
- func (enc *CustomEncoder) AddInt(k string, v int)
- func (enc *CustomEncoder) AddInt8(k string, v int8)
- func (enc *CustomEncoder) AddInt16(k string, v int16)
- func (enc *CustomEncoder) AddInt32(k string, v int32)
- func (enc *CustomEncoder) AddInt64(key string, val int64)
- func (enc *CustomEncoder) AddObject(key string, obj zapcore.ObjectMarshaler) error
- func (enc *CustomEncoder) AddReflected(key string, obj interface{}) error
- func (enc *CustomEncoder) AddString(key, val string)
- func (enc *CustomEncoder) AddTime(key string, val time.Time)
- func (enc *CustomEncoder) AddUint(k string, v uint)
- func (enc *CustomEncoder) AddUint8(k string, v uint8)
- func (enc *CustomEncoder) AddUint16(k string, v uint16)
- func (enc *CustomEncoder) AddUint32(k string, v uint32)
- func (enc *CustomEncoder) AddUint64(key string, val uint64)
- func (enc *CustomEncoder) AddUintptr(k string, v uintptr)
- func (enc *CustomEncoder) AppendArray(arr zapcore.ArrayMarshaler) error
- func (enc *CustomEncoder) AppendBool(val bool)
- func (enc *CustomEncoder) AppendByteString(val []byte)
- func (enc *CustomEncoder) AppendComplex64(v complex64)
- func (enc *CustomEncoder) AppendComplex128(v complex128)
- func (enc *CustomEncoder) AppendDuration(val time.Duration)
- func (enc *CustomEncoder) AppendFloat32(v float32)
- func (enc *CustomEncoder) AppendFloat64(v float64)
- func (enc *CustomEncoder) AppendInt(v int)
- func (enc *CustomEncoder) AppendInt8(v int8)
- func (enc *CustomEncoder) AppendInt16(v int16)
- func (enc *CustomEncoder) AppendInt32(v int32)
- func (enc *CustomEncoder) AppendInt64(val int64)
- func (enc *CustomEncoder) AppendObject(obj zapcore.ObjectMarshaler) error
- func (enc *CustomEncoder) AppendReflected(val interface{}) error
- func (enc *CustomEncoder) AppendString(val string)
- func (enc *CustomEncoder) AppendTime(val time.Time)
- func (enc *CustomEncoder) AppendTimeLayout(time time.Time, layout string)
- func (enc *CustomEncoder) AppendUint(v uint)
- func (enc *CustomEncoder) AppendUint8(v uint8)
- func (enc *CustomEncoder) AppendUint16(v uint16)
- func (enc *CustomEncoder) AppendUint32(v uint32)
- func (enc *CustomEncoder) AppendUint64(val uint64)
- func (enc *CustomEncoder) AppendUintptr(v uintptr)
- func (enc *CustomEncoder) Clone() zapcore.Encoder
- func (enc *CustomEncoder) EncodeEntry(ent zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)
- func (enc *CustomEncoder) OpenNamespace(key string)
- type CustomEncoderConfig
- type Logger
- func (l *Logger) AddCallerSkip(skip int) *Logger
- func (l *Logger) AddCore(newCore zapcore.Core) *Logger
- func (l *Logger) DPanic(args ...any)
- func (l *Logger) DPanicf(template string, args ...any)
- func (l *Logger) DPanicw(msg string, fields ...zap.Field)
- func (l *Logger) Debug(args ...any)
- func (l *Logger) Debugf(template string, args ...any)
- func (l *Logger) Debugw(msg string, fields ...zap.Field)
- func (l *Logger) Enabled(ctx context.Context, level slog.Level) bool
- func (l *Logger) Error(args ...any)
- func (l *Logger) ErrorDepth(depth int, args ...any)
- func (l *Logger) Errorf(template string, args ...any)
- func (l *Logger) Errorln(args ...any)
- func (l *Logger) Errorw(msg string, fields ...zap.Field)
- func (l *Logger) Fatal(args ...any)
- func (l *Logger) FatalDepth(depth int, args ...any)
- func (l *Logger) Fatalf(template string, args ...any)
- func (l *Logger) Fatalln(args ...any)
- func (l *Logger) Fatalw(msg string, fields ...zap.Field)
- func (l *Logger) Handle(ctx context.Context, record slog.Record) error
- func (l *Logger) Info(args ...any)
- func (l *Logger) InfoDepth(depth int, args ...any)
- func (l *Logger) Infof(template string, args ...any)
- func (l *Logger) Infoln(args ...any)
- func (l *Logger) Infow(msg string, fields ...zap.Field)
- func (l *Logger) Named(name string) *Logger
- func (l *Logger) NewSLogger() *slog.Logger
- func (l *Logger) Panic(args ...any)
- func (l *Logger) Panicf(template string, args ...any)
- func (l *Logger) Panicw(msg string, fields ...zap.Field)
- func (l *Logger) Print(args ...any)
- func (l *Logger) Printf(template string, args ...any)
- func (l *Logger) Println(args ...any)
- func (l *Logger) Sugar() *zap.SugaredLogger
- func (l *Logger) V(level int) bool
- func (l *Logger) Warn(args ...any)
- func (l *Logger) Warnf(template string, args ...any)
- func (l *Logger) Warning(args ...any)
- func (l *Logger) WarningDepth(depth int, args ...any)
- func (l *Logger) Warningf(template string, args ...any)
- func (l *Logger) Warningln(args ...any)
- func (l *Logger) Warnw(msg string, fields ...zap.Field)
- func (l *Logger) With(fields ...zap.Field) *Logger
- func (l *Logger) WithAttrs(attrs []slog.Attr) slog.Handler
- func (l *Logger) WithContext(ctx context.Context) *Logger
- func (l *Logger) WithGroup(name string) slog.Handler
- func (l *Logger) WithLazy(fields ...zap.Field) *Logger
- func (l *Logger) WithOptions(opts ...zap.Option) *Logger
- func (l *Logger) Zap() *zap.Logger
- type OtelConfig
- type StdErrLevel
- type StdOutLevel
- type ZipConfig
Constants ¶
const ( EncodingJson = "json" EncodingConsole = "console" )
const ( FieldStack = "stack" FieldApi = "api" FieldSource = "source" FieldResult = "result" FieldParam = "param" FieldFunc = "func" FieldMsg = "msg" FieldPosition = "position" FieldTraceId = "traceId" FieldSpanId = "spanId" FieldKey = "key" FieldValue = "value" FieldInvalid = "invalid" FieldIgnored = "ignored" FieldType = "type" FieldIP = "ip" FieldHostname = "hostname" FieldTime = "time" FieldApp = "app" FieldLevel = "level" FieldCaller = "caller" )
const ( EncodeLevelTypeColor = "color" EncodeLevelTypCapital = "capital" EncodeLevelTypeCapitalColor = "capitalColor" )
Variables ¶
This section is empty.
Functions ¶
func Check ¶
func Check(lvl zapcore.Level, args ...any) *zapcore.CheckedEntry
Check returns the result.
func DefaultReflectedEncoder ¶ added in v1.7.5
func DefaultReflectedEncoder(w io.Writer) zapcore.ReflectedEncoder
DefaultReflectedEncoder returns the result.
func FileWithLineNum ¶
func FileWithLineNum() string
FileWithLineNum return the file name and line number of the current file
func NewDevelopmentEncoderConfig ¶
func NewDevelopmentEncoderConfig() zapcore.EncoderConfig
NewDevelopmentEncoderConfig creates and returns a new instance.
func NewProductionEncoderConfig ¶
func NewProductionEncoderConfig() zapcore.EncoderConfig
NewProductionEncoderConfig creates and returns a new instance.
func SetDefaultLogger ¶
func SetDefaultLogger(logger *Logger)
SetDefaultLogger updates or inserts a value.
func ValueLevelNotify ¶ added in v1.3.15
func ValueLevelNotify[T constraintsx.Number](msg string, v, std T)
ValueLevelNotify performs the operation.
func ValueRangeNotify ¶ added in v1.3.15
ValueRangeNotify performs the operation.
Types ¶
type Config ¶
type Config struct {
Name string `json:"name,omitempty"` //system name namespace.service
LevelNumber int `json:"levelNumber,omitempty"`
// When EnableOtel is on, logs are also bridged to the OpenTelemetry log pipeline (via otelzap).
EnableOtel bool
Otel OtelConfig `json:"otel,omitempty"`
zap.Config
EncodeLevelType string `json:"encodeLevelType,omitempty" comment:"capital;capitalColor;color"`
TimeLayout string
Encoder zapcore.Encoder
}
func NewDevelopmentConfig ¶
NewDevelopmentConfig creates and returns a new instance.
func NewProductionConfig ¶
NewProductionConfig creates and returns a new instance.
type CustomEncoder ¶ added in v1.7.16
type CustomEncoder struct {
*CustomEncoderConfig
// contains filtered or unexported fields
}
func NewCustomEncoder ¶ added in v1.7.16
func NewCustomEncoder(cfg *CustomEncoderConfig) *CustomEncoder
NewCustomEncoder creates and returns a new instance.
func (*CustomEncoder) AddArray ¶ added in v1.7.16
func (enc *CustomEncoder) AddArray(key string, arr zapcore.ArrayMarshaler) error
AddArray updates or inserts a value.
func (*CustomEncoder) AddBinary ¶ added in v1.7.16
func (enc *CustomEncoder) AddBinary(key string, val []byte)
AddBinary updates or inserts a value.
func (*CustomEncoder) AddBool ¶ added in v1.7.16
func (enc *CustomEncoder) AddBool(key string, val bool)
AddBool updates or inserts a value.
func (*CustomEncoder) AddByteString ¶ added in v1.7.16
func (enc *CustomEncoder) AddByteString(key string, val []byte)
AddByteString updates or inserts a value.
func (*CustomEncoder) AddComplex64 ¶ added in v1.7.16
func (enc *CustomEncoder) AddComplex64(key string, val complex64)
AddComplex64 updates or inserts a value.
func (*CustomEncoder) AddComplex128 ¶ added in v1.7.16
func (enc *CustomEncoder) AddComplex128(key string, val complex128)
AddComplex128 updates or inserts a value.
func (*CustomEncoder) AddDuration ¶ added in v1.7.16
func (enc *CustomEncoder) AddDuration(key string, val time.Duration)
AddDuration updates or inserts a value.
func (*CustomEncoder) AddFloat32 ¶ added in v1.7.16
func (enc *CustomEncoder) AddFloat32(key string, val float32)
AddFloat32 updates or inserts a value.
func (*CustomEncoder) AddFloat64 ¶ added in v1.7.16
func (enc *CustomEncoder) AddFloat64(key string, val float64)
AddFloat64 updates or inserts a value.
func (*CustomEncoder) AddInt ¶ added in v1.7.16
func (enc *CustomEncoder) AddInt(k string, v int)
AddInt updates or inserts a value.
func (*CustomEncoder) AddInt8 ¶ added in v1.7.16
func (enc *CustomEncoder) AddInt8(k string, v int8)
AddInt8 updates or inserts a value.
func (*CustomEncoder) AddInt16 ¶ added in v1.7.16
func (enc *CustomEncoder) AddInt16(k string, v int16)
AddInt16 updates or inserts a value.
func (*CustomEncoder) AddInt32 ¶ added in v1.7.16
func (enc *CustomEncoder) AddInt32(k string, v int32)
AddInt32 updates or inserts a value.
func (*CustomEncoder) AddInt64 ¶ added in v1.7.16
func (enc *CustomEncoder) AddInt64(key string, val int64)
AddInt64 updates or inserts a value.
func (*CustomEncoder) AddObject ¶ added in v1.7.16
func (enc *CustomEncoder) AddObject(key string, obj zapcore.ObjectMarshaler) error
AddObject updates or inserts a value.
func (*CustomEncoder) AddReflected ¶ added in v1.7.16
func (enc *CustomEncoder) AddReflected(key string, obj interface{}) error
AddReflected updates or inserts a value.
func (*CustomEncoder) AddString ¶ added in v1.7.16
func (enc *CustomEncoder) AddString(key, val string)
AddString updates or inserts a value.
func (*CustomEncoder) AddTime ¶ added in v1.7.16
func (enc *CustomEncoder) AddTime(key string, val time.Time)
AddTime updates or inserts a value.
func (*CustomEncoder) AddUint ¶ added in v1.7.16
func (enc *CustomEncoder) AddUint(k string, v uint)
AddUint updates or inserts a value.
func (*CustomEncoder) AddUint8 ¶ added in v1.7.16
func (enc *CustomEncoder) AddUint8(k string, v uint8)
AddUint8 updates or inserts a value.
func (*CustomEncoder) AddUint16 ¶ added in v1.7.16
func (enc *CustomEncoder) AddUint16(k string, v uint16)
AddUint16 updates or inserts a value.
func (*CustomEncoder) AddUint32 ¶ added in v1.7.16
func (enc *CustomEncoder) AddUint32(k string, v uint32)
AddUint32 updates or inserts a value.
func (*CustomEncoder) AddUint64 ¶ added in v1.7.16
func (enc *CustomEncoder) AddUint64(key string, val uint64)
AddUint64 updates or inserts a value.
func (*CustomEncoder) AddUintptr ¶ added in v1.7.16
func (enc *CustomEncoder) AddUintptr(k string, v uintptr)
AddUintptr updates or inserts a value.
func (*CustomEncoder) AppendArray ¶ added in v1.7.16
func (enc *CustomEncoder) AppendArray(arr zapcore.ArrayMarshaler) error
AppendArray updates or inserts a value.
func (*CustomEncoder) AppendBool ¶ added in v1.7.16
func (enc *CustomEncoder) AppendBool(val bool)
AppendBool updates or inserts a value.
func (*CustomEncoder) AppendByteString ¶ added in v1.7.16
func (enc *CustomEncoder) AppendByteString(val []byte)
AppendByteString updates or inserts a value.
func (*CustomEncoder) AppendComplex64 ¶ added in v1.7.16
func (enc *CustomEncoder) AppendComplex64(v complex64)
AppendComplex64 updates or inserts a value.
func (*CustomEncoder) AppendComplex128 ¶ added in v1.7.16
func (enc *CustomEncoder) AppendComplex128(v complex128)
AppendComplex128 updates or inserts a value.
func (*CustomEncoder) AppendDuration ¶ added in v1.7.16
func (enc *CustomEncoder) AppendDuration(val time.Duration)
AppendDuration updates or inserts a value.
func (*CustomEncoder) AppendFloat32 ¶ added in v1.7.16
func (enc *CustomEncoder) AppendFloat32(v float32)
AppendFloat32 updates or inserts a value.
func (*CustomEncoder) AppendFloat64 ¶ added in v1.7.16
func (enc *CustomEncoder) AppendFloat64(v float64)
AppendFloat64 updates or inserts a value.
func (*CustomEncoder) AppendInt ¶ added in v1.7.16
func (enc *CustomEncoder) AppendInt(v int)
AppendInt updates or inserts a value.
func (*CustomEncoder) AppendInt8 ¶ added in v1.7.16
func (enc *CustomEncoder) AppendInt8(v int8)
AppendInt8 updates or inserts a value.
func (*CustomEncoder) AppendInt16 ¶ added in v1.7.16
func (enc *CustomEncoder) AppendInt16(v int16)
AppendInt16 updates or inserts a value.
func (*CustomEncoder) AppendInt32 ¶ added in v1.7.16
func (enc *CustomEncoder) AppendInt32(v int32)
AppendInt32 updates or inserts a value.
func (*CustomEncoder) AppendInt64 ¶ added in v1.7.16
func (enc *CustomEncoder) AppendInt64(val int64)
AppendInt64 updates or inserts a value.
func (*CustomEncoder) AppendObject ¶ added in v1.7.16
func (enc *CustomEncoder) AppendObject(obj zapcore.ObjectMarshaler) error
AppendObject updates or inserts a value.
func (*CustomEncoder) AppendReflected ¶ added in v1.7.16
func (enc *CustomEncoder) AppendReflected(val interface{}) error
AppendReflected updates or inserts a value.
func (*CustomEncoder) AppendString ¶ added in v1.7.16
func (enc *CustomEncoder) AppendString(val string)
AppendString updates or inserts a value.
func (*CustomEncoder) AppendTime ¶ added in v1.7.16
func (enc *CustomEncoder) AppendTime(val time.Time)
AppendTime updates or inserts a value.
func (*CustomEncoder) AppendTimeLayout ¶ added in v1.7.16
func (enc *CustomEncoder) AppendTimeLayout(time time.Time, layout string)
AppendTimeLayout updates or inserts a value.
func (*CustomEncoder) AppendUint ¶ added in v1.7.16
func (enc *CustomEncoder) AppendUint(v uint)
AppendUint updates or inserts a value.
func (*CustomEncoder) AppendUint8 ¶ added in v1.7.16
func (enc *CustomEncoder) AppendUint8(v uint8)
AppendUint8 updates or inserts a value.
func (*CustomEncoder) AppendUint16 ¶ added in v1.7.16
func (enc *CustomEncoder) AppendUint16(v uint16)
AppendUint16 updates or inserts a value.
func (*CustomEncoder) AppendUint32 ¶ added in v1.7.16
func (enc *CustomEncoder) AppendUint32(v uint32)
AppendUint32 updates or inserts a value.
func (*CustomEncoder) AppendUint64 ¶ added in v1.7.16
func (enc *CustomEncoder) AppendUint64(val uint64)
AppendUint64 updates or inserts a value.
func (*CustomEncoder) AppendUintptr ¶ added in v1.7.16
func (enc *CustomEncoder) AppendUintptr(v uintptr)
AppendUintptr updates or inserts a value.
func (*CustomEncoder) Clone ¶ added in v1.7.16
func (enc *CustomEncoder) Clone() zapcore.Encoder
Clone returns the result.
func (*CustomEncoder) EncodeEntry ¶ added in v1.7.16
func (enc *CustomEncoder) EncodeEntry(ent zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)
EncodeEntry formats or converts the value.
func (*CustomEncoder) OpenNamespace ¶ added in v1.7.16
func (enc *CustomEncoder) OpenNamespace(key string)
OpenNamespace creates and returns a new instance.
type CustomEncoderConfig ¶ added in v1.7.16
type CustomEncoderConfig struct {
*zapcore.EncoderConfig
TransferKey func(key string) string
}
type Logger ¶
func NewOtelLogger ¶ added in v1.8.2
NewOtelLogger creates and returns a new instance.
func (*Logger) AddCallerSkip ¶ added in v1.8.0
AddCallerSkip wrap the zap AddCallerSkip.
func (*Logger) DPanic ¶
DPanic uses fmt.Sprint to construct and log a message. In development, the logger then panics. (See DPanicLevel for details.)
func (*Logger) DPanicf ¶
DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)
func (*Logger) DPanicw ¶
DPanic logs a message at DPanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
If the logger is in development mode, it then panics (DPanic means "development panic"). This is useful for catching errors that are recoverable, but shouldn't ever happen.
func (*Logger) Debugw ¶
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 (*Logger) ErrorDepth ¶
ErrorDepth logs to ERROR log at the specified depth. Arguments are handled in the manner of fmt.Println.
func (*Logger) Errorw ¶
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 (*Logger) FatalDepth ¶
FatalDepth logs to FATAL log at the specified depth. Arguments are handled in the manner of fmt.Println.
func (*Logger) Fatalw ¶
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 (*Logger) InfoDepth ¶
InfoDepth logs to INFO log at the specified depth. Arguments are handled in the manner of fmt.Println.
func (*Logger) Infow ¶
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 (*Logger) NewSLogger ¶
NewSLogger creates and returns a new instance.
func (*Logger) Panicw ¶
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 (*Logger) WarningDepth ¶
WarningDepth logs to WARNING log at the specified depth. Arguments are handled in the manner of fmt.Println.
func (*Logger) Warnw ¶
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 (*Logger) With ¶
With wrap the zap With. Fields added to the child don't affect the parent, and vice versa.
func (*Logger) WithContext ¶ added in v1.8.2
WithContext updates or inserts a value.
func (*Logger) WithOptions ¶
WithOptions wrap the zap WithOptions, applies the supplied GzipOptions, and returns the resulting Logger. It's safe to use concurrently.