log

package
v1.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: MIT, Apache-2.0 Imports: 29 Imported by: 40

Documentation

Index

Constants

View Source
const (
	EncodingJson    = "json"
	EncodingConsole = "console"
)
View Source
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"
)
View Source
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 Context added in v1.9.0

func Context(ctx context.Context) zapcore.Field

Context returns the result.

func Debug

func Debug(args ...any)

Debug performs the operation.

func Debugf

func Debugf(template string, args ...any)

Debugf performs the operation.

func Debugw

func Debugw(msg string, fields ...zap.Field)

Debugw performs the operation.

func DefaultReflectedEncoder added in v1.7.5

func DefaultReflectedEncoder(w io.Writer) zapcore.ReflectedEncoder

DefaultReflectedEncoder returns the result.

func Error

func Error(args ...any)

Error returns the error message string.

func Errorf

func Errorf(template string, args ...any)

Errorf performs the operation.

func Errorw

func Errorw(msg string, fields ...zap.Field)

Errorw performs the operation.

func Fatal

func Fatal(args ...any)

Fatal performs the operation.

func Fatalf

func Fatalf(template string, args ...any)

Fatalf performs the operation.

func Fatalw

func Fatalw(msg string, fields ...zap.Field)

Fatalw performs the operation.

func FileWithLineNum

func FileWithLineNum() string

FileWithLineNum return the file name and line number of the current file

func Info

func Info(args ...any)

Info performs the operation.

func Infof

func Infof(template string, args ...any)

Infof performs the operation.

func Infow

func Infow(msg string, fields ...zap.Field)

Infow performs the operation.

func Log

func Log(lvl zapcore.Level, args ...any)

Log performs the operation.

func Logf

func Logf(lvl zapcore.Level, msg string, args ...any)

Logf performs the operation.

func Logw

func Logw(lvl zapcore.Level, msg string, fields ...zapcore.Field)

Logw performs the operation.

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 Panic

func Panic(args ...any)

Panic performs the operation.

func Panicf

func Panicf(template string, args ...any)

Panicf performs the operation.

func Panicw

func Panicw(msg string, fields ...zap.Field)

Panicw performs the operation.

func Printf

func Printf(template string, args ...any)

Printf performs the operation.

func Println

func Println(args ...any)

Println performs the operation.

func RawJson added in v1.11.8

func RawJson(key string, data []byte) zapcore.Field

RawJson returns the result.

func SetDefaultLogger

func SetDefaultLogger(logger *Logger)

SetDefaultLogger updates or inserts a value.

func Sync

func Sync() error

Sync performs the operation.

func TrimLineBreak

func TrimLineBreak(path string) string

TrimLineBreak returns the result.

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

func ValueRangeNotify[T cmp.Ordered](msg string, v, rangeMin, rangeMax T)

ValueRangeNotify performs the operation.

func Warn

func Warn(args ...any)

Warn performs the operation.

func Warnf

func Warnf(template string, args ...any)

Warnf performs the operation.

func Warnw

func Warnw(msg string, fields ...zap.Field)

Warnw 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

func NewDevelopmentConfig(appName string) *Config

NewDevelopmentConfig creates and returns a new instance.

func NewProductionConfig

func NewProductionConfig(appName string) *Config

NewProductionConfig creates and returns a new instance.

func (*Config) Init

func (lc *Config) Init()

Init performs the operation.

func (*Config) NewLogger

func (lc *Config) NewLogger(cores ...zapcore.Core) *Logger

NewLogger 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

type Logger struct {
	*zap.Logger
}

func CallerSkipLogger

func CallerSkipLogger(skip int) *Logger

range -3~6

func DefaultLogger

func DefaultLogger() *Logger

DefaultLogger returns the result.

func NewOtelLogger added in v1.8.2

func NewOtelLogger(name string, opts ...otelzap.Option) *Logger

NewOtelLogger creates and returns a new instance.

func NoCallerLogger

func NoCallerLogger() *Logger

NoCallerLogger returns the result.

func StackLogger

func StackLogger() *Logger

StackLogger returns the result.

func (*Logger) AddCallerSkip added in v1.8.0

func (l *Logger) AddCallerSkip(skip int) *Logger

AddCallerSkip wrap the zap AddCallerSkip.

func (*Logger) AddCore

func (l *Logger) AddCore(newCore zapcore.Core) *Logger

AddCore wrap the zap AddCore.

func (*Logger) DPanic

func (l *Logger) DPanic(args ...any)

DPanic uses fmt.Sprint to construct and log a message. In development, the logger then panics. (See DPanicLevel for details.)

func (*Logger) DPanicf

func (l *Logger) DPanicf(template string, args ...any)

DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)

func (*Logger) DPanicw

func (l *Logger) DPanicw(msg string, fields ...zap.Field)

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) Debug

func (l *Logger) Debug(args ...any)

Debug uses fmt.Sprint to construct and log a message.

func (*Logger) Debugf

func (l *Logger) Debugf(template string, args ...any)

Debugf uses fmt.Sprintf to log a templated message.

func (*Logger) Debugw

func (l *Logger) Debugw(msg string, fields ...zap.Field)

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) Enabled

func (l *Logger) Enabled(ctx context.Context, level slog.Level) bool

Enabled reports whether the condition holds.

func (*Logger) Error

func (l *Logger) Error(args ...any)

Error uses fmt.Sprint to construct and log a message.

func (*Logger) ErrorDepth

func (l *Logger) ErrorDepth(depth int, args ...any)

ErrorDepth logs to ERROR log at the specified depth. Arguments are handled in the manner of fmt.Println.

func (*Logger) Errorf

func (l *Logger) Errorf(template string, args ...any)

Errorf uses fmt.Sprintf to log a templated message.

func (*Logger) Errorln

func (l *Logger) Errorln(args ...any)

Errorln performs the operation.

func (*Logger) Errorw

func (l *Logger) Errorw(msg string, fields ...zap.Field)

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) Fatal

func (l *Logger) Fatal(args ...any)

Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.

func (*Logger) FatalDepth

func (l *Logger) FatalDepth(depth int, args ...any)

FatalDepth logs to FATAL log at the specified depth. Arguments are handled in the manner of fmt.Println.

func (*Logger) Fatalf

func (l *Logger) Fatalf(template string, args ...any)

Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.

func (*Logger) Fatalln

func (l *Logger) Fatalln(args ...any)

Fatalln performs the operation.

func (*Logger) Fatalw

func (l *Logger) Fatalw(msg string, fields ...zap.Field)

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) Handle

func (l *Logger) Handle(ctx context.Context, record slog.Record) error

Handle executes the operation.

func (*Logger) Info

func (l *Logger) Info(args ...any)

Info uses fmt.Sprint to construct and log a message.

func (*Logger) InfoDepth

func (l *Logger) InfoDepth(depth int, args ...any)

InfoDepth logs to INFO log at the specified depth. Arguments are handled in the manner of fmt.Println.

func (*Logger) Infof

func (l *Logger) Infof(template string, args ...any)

Infof uses fmt.Sprintf to log a templated message.

func (*Logger) Infoln

func (l *Logger) Infoln(args ...any)

Infoln performs the operation.

func (*Logger) Infow

func (l *Logger) Infow(msg string, fields ...zap.Field)

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) Named

func (l *Logger) Named(name string) *Logger

Named adds a sub-scope to the logger's name. See Logger.Named for details.

func (*Logger) NewSLogger

func (l *Logger) NewSLogger() *slog.Logger

NewSLogger creates and returns a new instance.

func (*Logger) Panic

func (l *Logger) Panic(args ...any)

Panic uses fmt.Sprint to construct and log a message, then panics.

func (*Logger) Panicf

func (l *Logger) Panicf(template string, args ...any)

Panicf uses fmt.Sprintf to log a templated message, then panics.

func (*Logger) Panicw

func (l *Logger) Panicw(msg string, fields ...zap.Field)

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) Print

func (l *Logger) Print(args ...any)

Print performs the operation.

func (*Logger) Printf

func (l *Logger) Printf(template string, args ...any)

Printf performs the operation.

func (*Logger) Println

func (l *Logger) Println(args ...any)

Println performs the operation.

func (*Logger) Sugar

func (l *Logger) Sugar() *zap.SugaredLogger

Sugar wrap the zap Sugar.

func (*Logger) V

func (l *Logger) V(level int) bool

grpclog

func (*Logger) Warn

func (l *Logger) Warn(args ...any)

Warn uses fmt.Sprint to construct and log a message.

func (*Logger) Warnf

func (l *Logger) Warnf(template string, args ...any)

Warnf uses fmt.Sprintf to log a templated message.

func (*Logger) Warning

func (l *Logger) Warning(args ...any)

Warning performs the operation.

func (*Logger) WarningDepth

func (l *Logger) WarningDepth(depth int, args ...any)

WarningDepth logs to WARNING log at the specified depth. Arguments are handled in the manner of fmt.Println.

func (*Logger) Warningf

func (l *Logger) Warningf(template string, args ...any)

grpclog

func (*Logger) Warningln

func (l *Logger) Warningln(args ...any)

Warningln performs the operation.

func (*Logger) Warnw

func (l *Logger) Warnw(msg string, fields ...zap.Field)

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

func (l *Logger) With(fields ...zap.Field) *Logger

With wrap the zap With. Fields added to the child don't affect the parent, and vice versa.

func (*Logger) WithAttrs

func (l *Logger) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs updates or inserts a value.

func (*Logger) WithContext added in v1.8.2

func (l *Logger) WithContext(ctx context.Context) *Logger

WithContext updates or inserts a value.

func (*Logger) WithGroup

func (l *Logger) WithGroup(name string) slog.Handler

WithGroup updates or inserts a value.

func (*Logger) WithLazy added in v1.8.0

func (l *Logger) WithLazy(fields ...zap.Field) *Logger

WithLazy updates or inserts a value.

func (*Logger) WithOptions

func (l *Logger) WithOptions(opts ...zap.Option) *Logger

WithOptions wrap the zap WithOptions, applies the supplied GzipOptions, and returns the resulting Logger. It's safe to use concurrently.

func (*Logger) Zap

func (l *Logger) Zap() *zap.Logger

Sugar wrap the zap Sugar.

type OtelConfig added in v1.11.8

type OtelConfig struct {
	Version        string                 `json:"version,omitempty"`
	SchemaURL      string                 `json:"schemaURL,omitempty"`
	Attributes     []attribute.KeyValue   `json:"attributes,omitempty"`
	LoggerProvider otellog.LoggerProvider `json:"loggerProvider,omitempty"`
}

type StdErrLevel

type StdErrLevel zapcore.Level

func (StdErrLevel) Enabled

func (l StdErrLevel) Enabled(lvl zapcore.Level) bool

Enabled reports whether the condition holds.

type StdOutLevel

type StdOutLevel zapcore.Level

func (StdOutLevel) Enabled

func (l StdOutLevel) Enabled(lvl zapcore.Level) bool

Enabled reports whether the condition holds.

type ZipConfig

type ZipConfig = zap.Config

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL