Documentation ¶
Index ¶
- func Config(app, level string)
- func Debug(msg string, fields ...Field)
- func Debugf(template string, args ...any)
- func Error(msg string, fields ...Field)
- func Errorf(template string, args ...any)
- func Fatal(msg string, fields ...Field)
- func Fatalf(template string, args ...any)
- func Info(msg string, fields ...Field)
- func Infof(template string, args ...any)
- func Panic(msg string, fields ...Field)
- func Panicf(template string, args ...any)
- func Warn(msg string, fields ...Field)
- func Warnf(template string, args ...any)
- type Field
- func Binary(key string, val []byte) Field
- func Bool(key string, val bool) Field
- func Boolp(key string, val *bool) Field
- func ByteString(key string, val []byte) Field
- func Duration(key string, val time.Duration) Field
- func Durationp(key string, val *time.Duration) Field
- func Float32(key string, val float32) Field
- func Float32p(key string, val *float32) Field
- func Float64(key string, val float64) Field
- func Float64p(key string, val *float64) Field
- func Int(key string, val int) Field
- func Int16(key string, val int16) Field
- func Int16p(key string, val *int16) Field
- func Int32(key string, val int32) Field
- func Int32p(key string, val *int32) Field
- func Int64(key string, val int64) Field
- func Int64p(key string, val *int64) Field
- func Int8(key string, val int8) Field
- func Int8p(key string, val *int8) Field
- func Intp(key string, val *int) Field
- func Namespace(key string) Field
- func Reflect(key string, val any) Field
- func Skip() Field
- func String(key string, val string) Field
- func Stringer(key string, val fmt.Stringer) Field
- func Stringp(key string, val *string) Field
- func Time(key string, val time.Time) Field
- func Timep(key string, val *time.Time) Field
- type FieldType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Config ¶
func Config(app, level string)
Config sets the application name ('app') value and the minimum enabled logging level
Default level value: "info". Accepted values: "panic", "fatal", "error", "warn", "warning", "info", "debug". In case of invalid input value, the log level is reset to default value.
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 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 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.
Types ¶
type Field ¶
A Field is a marshaling operation used to add a key-value pair to a logger's context. Most fields are lazily marshaled, so it's inexpensive to add fields to disabled debug-level log statements.
func Binary ¶
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 Boolp ¶
Boolp constructs a field that carries a *bool. The returned Field will safely and explicitly represent `nil` when appropriate.
func ByteString ¶
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 Duration ¶
Duration constructs a field with the given key and value. The encoder controls how the duration is serialized.
func Durationp ¶
Durationp constructs a field that carries a *time.Duration. The returned Field will safely and explicitly represent `nil` when appropriate.
func Float32 ¶
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 Float32p ¶
Float32p constructs a field that carries a *float32. The returned Field will safely and explicitly represent `nil` when appropriate.
func Float64 ¶
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 Float64p ¶
Float64p constructs a field that carries a *float64. The returned Field will safely and explicitly represent `nil` when appropriate.
func Int16p ¶
Int16p constructs a field that carries a *int16. The returned Field will safely and explicitly represent `nil` when appropriate.
func Int32p ¶
Int32p constructs a field that carries a *int32. The returned Field will safely and explicitly represent `nil` when appropriate.
func Int64p ¶
Int64p constructs a field that carries a *int64. The returned Field will safely and explicitly represent `nil` when appropriate.
func Int8p ¶
Int8p constructs a field that carries a *int8. The returned Field will safely and explicitly represent `nil` when appropriate.
func Intp ¶
Intp constructs a field that carries a *int. The returned Field will safely and explicitly represent `nil` when appropriate.
func Namespace ¶
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 subcomponents or third-party libraries.
func Reflect ¶
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 Stringer ¶
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 Stringp ¶
Stringp constructs a field that carries a *string. The returned Field will safely and explicitly represent `nil` when appropriate.
type FieldType ¶
type FieldType uint8
A FieldType indicates which member of the Field union struct should be used and how it should be serialized.
const ( // UnknownType is the default field type. Attempting to add it to an encoder will panic. UnknownType FieldType = iota // BinaryType indicates that the field carries an opaque binary blob. BinaryType // BoolType indicates that the field carries a bool. BoolType // ByteStringType indicates that the field carries UTF-8 encoded bytes. ByteStringType // DurationType indicates that the field carries a time.Duration. DurationType // Float64Type indicates that the field carries a float64. Float64Type // Float32Type indicates that the field carries a float32. Float32Type // Int64Type indicates that the field carries an int64. Int64Type // Int32Type indicates that the field carries an int32. Int32Type // Int16Type indicates that the field carries an int16. Int16Type // Int8Type indicates that the field carries an int8. Int8Type // StringType indicates that the field carries a string. StringType // TimeType indicates that the field carries a time.Time that is // representable by a UnixNano() stored as an int64. TimeType // TimeFullType indicates that the field carries a time.Time stored as-is. TimeFullType // ReflectType indicates that the field carries an interface{}, which should // be serialized using reflection. ReflectType // NamespaceType signals the beginning of an isolated namespace. All // subsequent fields should be added to the new namespace. NamespaceType // StringerType indicates that the field carries a fmt.Stringer. StringerType // ErrorType indicates that the field carries an error. ErrorType // SkipType indicates that the field is a no-op. SkipType )