Documentation
¶
Overview ¶
nolint:forcetypeassert,gochecknoglobals,mnd
nolint:exhaustive,dupl
nolint:err113
nolint:exhaustive,dupl
nolint:gochecknoglobals,mnd
Index ¶
- Constants
- func LogLevelFuncForError(err error, logger Logger) func(ctx context.Context, message any, fields ...Field)
- func StdLoggerWithLevel(adapter Logger, level Level, withFields ...Field) *stdlog.Logger
- func ToContext(ctx context.Context, fields ...Field) context.Context
- type Adapter
- func (l *Adapter) Close() error
- func (l *Adapter) Debug(ctx context.Context, msg any, fields ...Field)
- func (l *Adapter) Error(ctx context.Context, msg any, fields ...Field)
- func (l *Adapter) Fatal(ctx context.Context, msg any, fields ...Field)
- func (l *Adapter) Info(ctx context.Context, msg any, fields ...Field)
- func (l *Adapter) IsLevelEnabled(level Level) bool
- func (l *Adapter) Level() Level
- func (l *Adapter) Log(ctx context.Context, level Level, msg any, fields ...Field)
- func (l *Adapter) Panic(ctx context.Context, msg any, fields ...Field)
- func (l *Adapter) Print(ctx context.Context, msg any, fields ...Field)
- func (l *Adapter) SetLogLevel(lvl Level)
- func (l *Adapter) Trace(ctx context.Context, msg any, fields ...Field)
- func (l *Adapter) Warn(ctx context.Context, msg any, fields ...Field)
- type Encoder
- type Field
- func Any(name string, value any) Field
- func Bool(name string, value bool) Field
- func Bools(name string, values []bool) Field
- func ByteString(name string, value []byte) Field
- func ContextLogValues(ctx context.Context) []Field
- func Dictionary(name string, value map[string]any) Field
- func Duration(name string, value time.Duration) Field
- func Durations(name string, values []time.Duration) Field
- func Error(err error) Field
- func Float32(name string, value float32) Field
- func Float64(name string, value float64) Field
- func Floats32(name string, values []float32) Field
- func Floats64(name string, values []float64) Field
- func Int(name string, value int) Field
- func Int16(name string, value int16) Field
- func Int32(name string, value int32) Field
- func Int64(name string, value int64) Field
- func Int8(name string, value int8) Field
- func Ints(name string, values []int) Field
- func Ints16(name string, values []int16) Field
- func Ints32(name string, values []int32) Field
- func Ints64(name string, values []int64) Field
- func Ints8(name string, values []int8) Field
- func Object(name string, values any) Field
- func Objects(name string, values []any) Field
- func String(name string, value string) Field
- func Stringer(name string, value fmt.Stringer) Field
- func Strings(name string, values []string) Field
- func Time(name string, value time.Time) Field
- func Times(name string, values []time.Time) Field
- func Uint(name string, value uint) Field
- func Uint16(name string, value uint16) Field
- func Uint32(name string, value uint32) Field
- func Uint64(name string, value uint64) Field
- func Uint8(name string, value uint8) Field
- func Uints(name string, values []uint) Field
- func Uints16(name string, values []uint16) Field
- func Uints32(name string, values []uint32) Field
- func Uints64(name string, values []uint64) Field
- func Uints8(name string, values []uint8) Field
- type FieldType
- type JsonEncoder
- type Level
- type LogLevelSpecifier
- type Logger
- type LoggerWriter
- type Option
- func WithEncoder(encoder Encoder) Option
- func WithExitFunction(f exitFunc) Option
- func WithFieldsDeduplication(deduplicateFields bool) Option
- func WithLevel(level Level) Option
- func WithOutput(w ...io.Writer) Option
- func WithReportCaller(reportCaller bool) Option
- func WithTimeNow(timeNow func() time.Time) Option
- func WithTimestamp(enableTimestamp bool) Option
- type PlainTextEncoder
Constants ¶
const ( FieldKeyTime = "time" FieldKeyLevel = "level" FieldKeyMsg = "msg" FieldKeyLogError = "error" FieldKeyFunc = "func" FieldKeyFile = "file" )
Default field names for the default fields
Variables ¶
This section is empty.
Functions ¶
func LogLevelFuncForError ¶
func LogLevelFuncForError(err error, logger Logger) func(ctx context.Context, message any, fields ...Field)
nolint:exhaustive
func StdLoggerWithLevel ¶
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
func (*Adapter) IsLevelEnabled ¶
func (*Adapter) SetLogLevel ¶ added in v1.5.1
type FieldType ¶ added in v1.6.0
type FieldType uint8
A FieldType indicates which member of the Field union struct should be used and how it should be serialized.
const ( UnknownType FieldType = iota BoolType Float32Type Float64Type IntType UintType StringType TimeType DurationType ObjectType ErrorType ArrBoolType ArrFloat32Type ArrFloat64Type ArrIntType ArrUintType ArrStringType ArrTimeType ArrDurationType ArrObjectType ReflectType ArrReflectType DictionaryType )
type JsonEncoder ¶ added in v1.6.0
type JsonEncoder struct{}
type Level ¶
type Level uint32 // nolint:recvcheck
const ( // PanicLevel level, highest level of severity. Logs and then calls panic with the // message passed to Debug, Info, ... PanicLevel Level = iota // FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the // logging level is set to Panic. FatalLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // InfoLevel level. General operational entries about what's going on inside the // application. InfoLevel // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel )
These are the different logging levels. You can set the logging level to log on your instance of logger
func LogLevelForError ¶
func ParseLogLevel ¶
func (Level) MarshalText ¶ added in v1.7.0
MarshalText marshals the Level to text. Note that the text representation drops the -Level suffix (see example).
func (*Level) UnmarshalText ¶ added in v1.7.0
UnmarshalText unmarshals text to a level. Like MarshalText, UnmarshalText expects the text representation of a Level to drop the -Level suffix (see example).
In particular, this makes it easy to configure logging levels using YAML, TOML, or JSON files.
type LogLevelSpecifier ¶
type LogLevelSpecifier interface {
LogLevel() Level
}
type Logger ¶
type Logger interface { Log(ctx context.Context, level Level, msg any, fields ...Field) Trace(ctx context.Context, msg any, fields ...Field) Debug(ctx context.Context, msg any, fields ...Field) Info(ctx context.Context, msg any, fields ...Field) Warn(ctx context.Context, msg any, fields ...Field) Error(ctx context.Context, msg any, fields ...Field) Fatal(ctx context.Context, msg any, fields ...Field) Panic(ctx context.Context, msg any, fields ...Field) }
type LoggerWriter ¶
type LoggerWriter struct {
// contains filtered or unexported fields
}
type Option ¶ added in v1.4.0
type Option func(*Adapter)
func WithEncoder ¶ added in v1.6.0
func WithExitFunction ¶ added in v1.4.0
func WithExitFunction(f exitFunc) Option
func WithFieldsDeduplication ¶ added in v1.6.0
func WithOutput ¶ added in v1.4.0
func WithReportCaller ¶ added in v1.4.0
func WithTimeNow ¶ added in v1.6.0
func WithTimestamp ¶ added in v1.6.0
type PlainTextEncoder ¶ added in v1.6.0
type PlainTextEncoder struct{}