slogx

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: GPL-3.0 Imports: 7 Imported by: 2

Documentation

Overview

slogx is extension of slog package and logger package. It provides additional attributes and helper functions for logging.

Index

Constants

View Source
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

func Any(key string, value any) slog.Attr

Any returns an slog.Attr for the supplied value. See [AnyValue] for how values are treated.

func Binary

func Binary(key string, v []byte) slog.Attr

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 Bool

func Bool(key string, v bool) slog.Attr

Bool returns an slog.Attr for a bool.

func ByteString

func ByteString(key string, v []byte) slog.Attr

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

func Duration(key string, v time.Duration) slog.Attr

Duration returns an slog.Attr for a time.Duration.

func Error

func Error(err error) slog.Attr

Error returns an slog.Attr for an error value.

func Float32

func Float32(key string, v float32) slog.Attr

Float32 converts a float32 to a float64 and returns an slog.Attr with that value.

func Float64

func Float64(key string, v float64) slog.Attr

Float64 returns an slog.Attr for a floating-point number.

func Group

func Group(key string, args ...any) slog.Attr

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 Int

func Int(key string, value int) slog.Attr

Int converts an int to an int64 and returns an slog.Attr with that value.

func Int16

func Int16(key string, value int16) slog.Attr

Int16 converts an int16 to an int64 and returns

func Int32

func Int32(key string, value int32) slog.Attr

Int32 converts an int32 to an int64 and returns

func Int64

func Int64(key string, value int64) slog.Attr

Int64 returns an slog.Attr for an int64.

func Int8

func Int8(key string, value int8) slog.Attr

Int8 converts an int8 to an int64 and returns

func NamedError

func NamedError(key string, err error) slog.Attr

NamedError returns an slog.Attr for an error value with a key.

func Reflect

func Reflect(key string, v interface{}) slog.Attr

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

func Stack(key string) slog.Attr

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

func StackSkip(key string, skip int) slog.Attr

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.

func String

func String(key, value string) slog.Attr

String returns an slog.Attr for a string value.

func Stringer

func Stringer(key string, value fmt.Stringer) slog.Attr

Stringer returns an slog.Attr for a fmt.Stringer value.

func Time

func Time(key string, v time.Time) slog.Attr

Time returns an slog.Attr for a time.Time. It discards the monotonic portion.

func Uint

func Uint(key string, v uint) slog.Attr

Uint converts a uint to a uint64 and returns

func Uint16

func Uint16(key string, v uint16) slog.Attr

Uint16 converts a uint16 to a uint64 and returns

func Uint32

func Uint32(key string, v uint32) slog.Attr

Uint32 converts a uint32 to a uint64 and returns

func Uint64

func Uint64(key string, v uint64) slog.Attr

Uint64 returns an slog.Attr for a uint64.

func Uint8

func Uint8(key string, v uint8) slog.Attr

Uint8 converts a uint8 to a uint64 and returns

func Uintptr

func Uintptr(key string, v uintptr) slog.Attr

Uintptr returns an slog.Attr for a uintptr.

Types

This section is empty.

Jump to

Keyboard shortcuts

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