log

package
v0.21.26 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DebugLevel = zapcore.DebugLevel
	InfoLevel  = zapcore.InfoLevel
	WarnLevel  = zapcore.WarnLevel
	ErrorLevel = zapcore.ErrorLevel
	PanicLevel = zapcore.PanicLevel
	FatalLevel = zapcore.FatalLevel
)

Variables

This section is empty.

Functions

func Span

func Span(ctx context.Context, attrs ...attribute.KeyValue) trace.Span

Types

type CallerEncoder

type CallerEncoder = zapcore.CallerEncoder

type CheckedEntry

type CheckedEntry = zapcore.CheckedEntry

type Core

type Core = zapcore.Core

type DurationEncoder

type DurationEncoder = zapcore.DurationEncoder

type Encoder

type Encoder = zapcore.Encoder

type EncoderBuilder

type EncoderBuilder struct {
	// contains filtered or unexported fields
}

func NewEncoderBuilder

func NewEncoderBuilder() *EncoderBuilder

func (*EncoderBuilder) ConsoleEncoder

func (eb *EncoderBuilder) ConsoleEncoder() Encoder

func (*EncoderBuilder) JsonEncoder

func (eb *EncoderBuilder) JsonEncoder() Encoder

func (*EncoderBuilder) SensitiveEncoder

func (eb *EncoderBuilder) SensitiveEncoder() Encoder

func (*EncoderBuilder) WithCallerKey

func (eb *EncoderBuilder) WithCallerKey(key string) *EncoderBuilder

func (*EncoderBuilder) WithLevelKey

func (eb *EncoderBuilder) WithLevelKey(key string) *EncoderBuilder

func (*EncoderBuilder) WithMessageKey

func (eb *EncoderBuilder) WithMessageKey(key string) *EncoderBuilder

func (*EncoderBuilder) WithNameKey

func (eb *EncoderBuilder) WithNameKey(key string) *EncoderBuilder

func (*EncoderBuilder) WithTimeKey

func (eb *EncoderBuilder) WithTimeKey(key string) *EncoderBuilder

type Entry

type Entry = zapcore.Entry

type Field

type Field = zapcore.Field

func Binary

func Binary(key string, val []byte) Field

Binary constructs a field that carries an opaque binary blob.

Binary data is serialized in an encoding-appropriate format. For example, zap's JSON encoder base64-encodes binary blobs. To log UTF-8 encoded text, use ByteString.

func Bool

func Bool(key string, val bool) Field

Bool constructs a field that carries a bool.

func BoolPtr

func BoolPtr(key string, val *bool) Field

BoolPtr constructs a field that carries a *bool. The returned Field will safely and explicitly represent `nil` when appropriate.

func ByteString

func ByteString(key string, val []byte) Field

ByteString constructs a field that carries UTF-8 encoded text as a []byte. To log opaque binary blobs (which aren't necessarily valid UTF-8), use Binary.

func Complex64

func Complex64(key string, val complex64) Field

Complex64 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex64 to interface{}).

func Complex64Ptr

func Complex64Ptr(key string, val *complex64) Field

Complex64Ptr constructs a field that carries a *complex64. The returned Field will safely and explicitly represent `nil` when appropriate.

func Complex128

func Complex128(key string, val complex128) Field

Complex128 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex128 to interface{}).

func Complex128Ptr

func Complex128Ptr(key string, val *complex128) Field

Complex128Ptr constructs a field that carries a *complex128. The returned Field will safely and explicitly represent `nil` when appropriate.

func Duration

func Duration(key string, val time.Duration) Field

Duration constructs a field with the given key and value. The encoder controls how the duration is serialized.

func DurationPtr

func DurationPtr(key string, val *time.Duration) Field

DurationPtr constructs a field that carries a *time.Duration. The returned Field will safely and explicitly represent `nil` when appropriate.

func Error

func Error(err error) Field

Error is shorthand for the common idiom NamedError("error", err).

func Float32

func Float32(key string, val float32) Field

Float32 constructs a field that carries a float32. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.

func Float32Ptr

func Float32Ptr(key string, val *float32) Field

Float32Ptr constructs a field that carries a *float32. The returned Field will safely and explicitly represent `nil` when appropriate.

func Float64

func Float64(key string, val float64) Field

Float64 constructs a field that carries a float64. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.

func Float64Ptr

func Float64Ptr(key string, val *float64) Field

Float64Ptr constructs a field that carries a *float64. The returned Field will safely and explicitly represent `nil` when appropriate.

func Inline

func Inline(val zapcore.ObjectMarshaler) Field

Inline constructs a Field that is similar to Object, but it will add the elements of the provided ObjectMarshaller to the current namespace.

func Int

func Int(key string, val int) Field

Int constructs a field with the given key and value.

func Int8

func Int8(key string, val int8) Field

Int8 constructs a field with the given key and value.

func Int8Ptr

func Int8Ptr(key string, val *int8) Field

Int8Ptr constructs a field that carries a *int8. The returned Field will safely and explicitly represent `nil` when appropriate.

func Int16

func Int16(key string, val int16) Field

Int16 constructs a field with the given key and value.

func Int16Ptr

func Int16Ptr(key string, val *int16) Field

Int16Ptr constructs a field that carries a *int16. The returned Field will safely and explicitly represent `nil` when appropriate.

func Int32

func Int32(key string, val int32) Field

Int32 constructs a field with the given key and value.

func Int32Ptr

func Int32Ptr(key string, val *int32) Field

Int32Ptr constructs a field that carries a *int32. The returned Field will safely and explicitly represent `nil` when appropriate.

func Int64

func Int64(key string, val int64) Field

Int64 constructs a field with the given key and value.

func Int64Ptr

func Int64Ptr(key string, val *int64) Field

Int64Ptr constructs a field that carries a *int64. The returned Field will safely and explicitly represent `nil` when appropriate.

func IntPtr

func IntPtr(key string, val *int) Field

IntPtr constructs a field that carries a *int. The returned Field will safely and explicitly represent `nil` when appropriate.

func NamedError

func NamedError(key string, err error) Field

NamedError constructs a field that lazily stores err.Error() under the provided key. Errors which also implement fmt.Formatter (like those produced by github.com/pkg/errors) will also have their verbose representation stored under key+"Verbose". If passed a nil error, the field is a no-op.

For the common case in which the key is simply "error", the Error function is shorter and less repetitive.

func Namespace

func Namespace(key string) Field

Namespace creates a named, isolated scope within the logger's context. All subsequent fields will be added to the new namespace.

This helps prevent key collisions when injecting loggers into sub-components or third-party libraries.

func Object

func Object(key string, val zapcore.ObjectMarshaler) Field

Object constructs a field with the given key and ObjectMarshaler. It provides a flexible, but still type-safe and efficient, way to add map- or struct-like user-defined types to the logging context. The struct's MarshalLogObject method is called lazily.

func Reflect

func Reflect(key string, val interface{}) Field

Reflect constructs a field with the given key and an arbitrary object. It uses an encoding-appropriate, reflection-based function to lazily serialize nearly any object into the logging context, but it's relatively slow and allocation-heavy. Outside tests, Any is always a better choice.

If encoding fails (e.g., trying to serialize a map[int]string to JSON), Reflect includes the error message in the final log output.

func Skip

func Skip() Field

Skip constructs a no-op field, which is often useful when handling invalid inputs in other Field constructors.

func String

func String(key string, val string) Field

String constructs a field with the given key and value.

func StringPtr

func StringPtr(key string, val *string) Field

StringPtr constructs a field that carries a *string. The returned Field will safely and explicitly represent `nil` when appropriate.

func Stringer

func Stringer(key string, val fmt.Stringer) Field

Stringer constructs a field with the given key and the output of the value's String method. The Stringer's String method is called lazily.

func Strings

func Strings(key string, ss []string) Field

Strings constructs a field that carries a slice of strings.

func Time

func Time(key string, val time.Time) Field

Time constructs a Field with the given key and value. The encoder controls how the time is serialized.

func TimePtr

func TimePtr(key string, val *time.Time) Field

TimePtr constructs a field that carries a *time.Time. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uint

func Uint(key string, val uint) Field

Uint constructs a field with the given key and value.

func Uint8

func Uint8(key string, val uint8) Field

Uint8 constructs a field with the given key and value.

func Uint8Ptr

func Uint8Ptr(key string, val *uint8) Field

Uint8Ptr constructs a field that carries a *uint8. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uint16

func Uint16(key string, val uint16) Field

Uint16 constructs a field with the given key and value.

func Uint16Ptr

func Uint16Ptr(key string, val *uint16) Field

Uint16Ptr constructs a field that carries a *uint16. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uint32

func Uint32(key string, val uint32) Field

Uint32 constructs a field with the given key and value.

func Uint32Ptr

func Uint32Ptr(key string, val *uint32) Field

Uint32Ptr constructs a field that carries a *uint32. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uint64

func Uint64(key string, val uint64) Field

Uint64 constructs a field with the given key and value.

func Uint64Ptr

func Uint64Ptr(key string, val *uint64) Field

Uint64Ptr constructs a field that carries a *uint64. The returned Field will safely and explicitly represent `nil` when appropriate.

func UintPtr

func UintPtr(key string, val *uint) Field

UintPtr constructs a field that carries a *uint. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uintptr

func Uintptr(key string, val uintptr) Field

Uintptr constructs a field with the given key and value.

func UintptrPtr

func UintptrPtr(key string, val *uintptr) Field

UintptrPtr constructs a field that carries a *uintptr. The returned Field will safely and explicitly represent `nil` when appropriate.

type FieldType

type FieldType = zapcore.FieldType

type Hook

type Hook = func(entry Entry) error

type Level

type Level = zapcore.Level

type LevelEncoder

type LevelEncoder = zapcore.LevelEncoder

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is a wrapper around zap.Logger and adds a good few features to it. It provides layered logs which could be used by separate packages, and could be turned off or on separately. Separate layers could also have independent log levels. Whenever you change log level it propagates through its children.

var (
	DefaultLogger *Logger
	NopLogger     *Logger
)

func New

func New(opts ...Option) *Logger

func (*Logger) Check

func (l *Logger) Check(lvl Level, msg string) *CheckedEntry

func (*Logger) Debug

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

func (*Logger) DebugCtx

func (l *Logger) DebugCtx(ctx context.Context, msg string, fields ...Field)

func (*Logger) Error

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

func (*Logger) ErrorCtx

func (l *Logger) ErrorCtx(ctx context.Context, msg string, fields ...Field)

func (*Logger) ErrorOnErr

func (l *Logger) ErrorOnErr(guideTxt string, err error, fields ...Field)

func (*Logger) Fatal

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

func (*Logger) FatalCtx

func (l *Logger) FatalCtx(ctx context.Context, msg string, fields ...Field)

func (*Logger) Info

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

func (*Logger) InfoCtx

func (l *Logger) InfoCtx(ctx context.Context, msg string, fields ...Field)

func (*Logger) LogEvent

func (l *Logger) LogEvent(event fxevent.Event)

func (*Logger) RecoverPanic

func (l *Logger) RecoverPanic(funcName string, extraInfo interface{}, compensationFunc func())

func (*Logger) SetLevel

func (l *Logger) SetLevel(lvl Level)

func (*Logger) Sugared

func (l *Logger) Sugared() *SugaredLogger

func (*Logger) Sync

func (l *Logger) Sync() error

func (*Logger) Warn

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

func (*Logger) WarnCtx

func (l *Logger) WarnCtx(ctx context.Context, msg string, fields ...Field)

func (*Logger) WarnOnErr

func (l *Logger) WarnOnErr(guideTxt string, err error, fields ...Field)

func (*Logger) With

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

func (*Logger) WithCore

func (l *Logger) WithCore(core Core) *Logger

func (*Logger) WithSkip

func (l *Logger) WithSkip(name string, skipCaller int) *Logger

type Option

type Option func(cfg *config)

func WithConsole

func WithConsole() Option

func WithCore

func WithCore(cores ...Core) Option

func WithHook

func WithHook(hooks ...Hook) Option

func WithJSON

func WithJSON() Option

func WithLevel

func WithLevel(lvl Level) Option

func WithSkipCaller

func WithSkipCaller(skip int) Option

type Sensitive

type Sensitive struct {
	zapcore.Encoder
}

func (Sensitive) Clone

func (s Sensitive) Clone() zapcore.Encoder

func (Sensitive) EncodeEntry

func (s Sensitive) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)

type SugaredLogger

type SugaredLogger struct {
	// contains filtered or unexported fields
}

func (SugaredLogger) Debug

func (l SugaredLogger) Debug(template string, args ...any)

func (SugaredLogger) DebugCtx

func (l SugaredLogger) DebugCtx(ctx context.Context, template string, args ...any)

func (SugaredLogger) Error

func (l SugaredLogger) Error(template string, args ...any)

func (SugaredLogger) ErrorCtx

func (l SugaredLogger) ErrorCtx(ctx context.Context, template string, args ...any)

func (SugaredLogger) Fatal

func (l SugaredLogger) Fatal(template string, args ...any)

func (SugaredLogger) Info

func (l SugaredLogger) Info(template string, args ...any)

func (SugaredLogger) InfoCtx

func (l SugaredLogger) InfoCtx(ctx context.Context, template string, args ...any)

func (SugaredLogger) Warn

func (l SugaredLogger) Warn(template string, args ...any)

func (SugaredLogger) WarnCtx

func (l SugaredLogger) WarnCtx(ctx context.Context, template string, args ...any)

type TimeEncoder

type TimeEncoder = zapcore.TimeEncoder

Jump to

Keyboard shortcuts

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