Documentation ¶
Overview ¶
slogx is extension of slog package and logger package. It provides additional attributes and helper functions for logging.
Index ¶
- Constants
- func Any(key string, value any) slog.Attr
- func Binary(key string, v []byte) slog.Attr
- func Bool(key string, v bool) slog.Attr
- func ByteString(key string, v []byte) slog.Attr
- func Duration(key string, v time.Duration) slog.Attr
- func Error(err error) slog.Attr
- func Float32(key string, v float32) slog.Attr
- func Float64(key string, v float64) slog.Attr
- func Group(key string, args ...any) slog.Attr
- func Int(key string, value int) slog.Attr
- func Int16(key string, value int16) slog.Attr
- func Int32(key string, value int32) slog.Attr
- func Int64(key string, value int64) slog.Attr
- func Int8(key string, value int8) slog.Attr
- func NamedError(key string, err error) slog.Attr
- func Reflect(key string, v interface{}) slog.Attr
- func Stack(key string) slog.Attr
- func StackSkip(key string, skip int) slog.Attr
- func String(key, value string) slog.Attr
- func Stringer(key string, value fmt.Stringer) slog.Attr
- func Time(key string, v time.Time) slog.Attr
- func Uint(key string, v uint) slog.Attr
- func Uint16(key string, v uint16) slog.Attr
- func Uint32(key string, v uint32) slog.Attr
- func Uint64(key string, v uint64) slog.Attr
- func Uint8(key string, v uint8) slog.Attr
- func Uintptr(key string, v uintptr) slog.Attr
Constants ¶
const ( TimeKey = slog.TimeKey LevelKey = slog.LevelKey MessageKey = slog.MessageKey SourceKey = slog.SourceKey ErrorKey = "error" ErrorVerboseKey = "error_verbose" ErrorStackTraceKey = "error_stacktrace" )
Keys for log attributes.
Variables ¶
This section is empty.
Functions ¶
func Any ¶
Any returns an slog.Attr for the supplied value. See [AnyValue] for how values are treated.
func Binary ¶
Binary returns an slog.Attr for a 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 ByteString ¶
ByteString returns an slog.Attr for a UTF-8 encoded byte string.
To log opaque binary blobs (which aren't necessarily valid UTF-8), use Binary.
func Duration ¶
Duration returns an slog.Attr for a time.Duration.
func Group ¶
Group returns an slog.Attr for a Group [Value]. The first argument is the key; the remaining arguments are converted to Attrs as in [Logger.Log].
Use Group to collect several key-value pairs under a single key on a log line, or as the result of LogValue in order to log a single value as multiple Attrs.
func NamedError ¶
NamedError returns an slog.Attr for an error value with a key.
func Reflect ¶
Reflect returns an slog.Attr for an arbitrary object. It uses an json encoding, reflection-based function to lazily serialize nearly any object into an slog.Attr, but it's relatively slow and allocation-heavy. Any is always a better choice.
func Stack ¶
Stack returns an slog.Attr for the current stack trace. Keep in mind that taking a stacktrace is eager and expensive (relatively speaking); this function both makes an allocation and takes about two microseconds.
func StackSkip ¶
StackSkip returns an slog.Attr for the stack trace similarly to Stack, but also skips the given number of frames from the top of the stacktrace.
Types ¶
This section is empty.