Documentation ¶
Index ¶
- Constants
- func Any(key string, value any) slog.Attr
- func Bool(key string, value bool) slog.Attr
- func Duration(key string, value time.Duration) slog.Attr
- func Float64(key string, value float64) slog.Attr
- func Group(key string, args ...any) slog.Attr
- func Int(key string, value int) slog.Attr
- func Int64(key string, value int64) slog.Attr
- func SetConfig(cfg Config)
- func SetConfigOverride(name string, cfg Config)
- func SetConfigOverrides(text string)
- func String(key string, value string) slog.Attr
- func Time(key string, value time.Time) slog.Attr
- func Uint64(key string, value uint64) slog.Attr
- type Config
- type Logger
- func (l *Logger) Error(msg string, args ...slog.Attr)
- func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...slog.Attr)
- func (l *Logger) ErrorContextE(ctx context.Context, msg string, err error, args ...slog.Attr)
- func (l *Logger) ErrorE(msg string, err error, args ...slog.Attr)
- func (l *Logger) Info(msg string, args ...slog.Attr)
- func (l *Logger) InfoContext(ctx context.Context, msg string, args ...slog.Attr)
- func (l *Logger) WithAttrs(attrs ...slog.Attr) *Logger
- func (l *Logger) WithGroup(name string) *Logger
Constants ¶
const ( // LevelDebug specifies info log level. LevelInfo = "info" // LevelDebug specifies error log level. LevelError = "error" // FormatText specifies text output for a logger. FormatText = "text" // FormatJSON specifies json output for a logger. FormatJSON = "json" // OutputStdout specifies stdout output for a logger. OutputStdout = "stdout" // OutputStderr specifies stderr output for a logger. OutputStderr = "stderr" )
Variables ¶
This section is empty.
Functions ¶
func Int ¶ added in v0.0.5
Int converts an int to an int64 and returns an slog.Attr with that value.
func SetConfig ¶ added in v0.0.3
func SetConfig(cfg Config)
SetConfig sets the config values for all loggers.
func SetConfigOverride ¶ added in v0.0.3
SetConfigOverride sets the config override for the given named logger.
func SetConfigOverrides ¶ added in v0.0.3
func SetConfigOverrides(text string)
SetConfigOverrides parses and sets config overrides from the given text.
Overrides are separated by ";", and override values are comma separated, where the first value is the name, and the remaining values are key value pairs separated by "=".
Types ¶
type Config ¶
type Config struct { // Level specifies the logging level. Level string // Format specifies the output format of the logger. Format string // EnableStackTrace enables logging error stack traces. EnableStackTrace bool // EnableSource enables logging the source location. EnableSource bool // Output specifies the output path for the logger. Output string // DisableColor specifies if colored output is disabled. DisableColor bool }
Config contains general settings for a logger.
func DefaultConfig ¶ added in v0.0.3
func DefaultConfig() Config
DefaultConfig returns a config with default values.
The default values are derived from environment variables.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a logger that wraps the slog package.
func (*Logger) ErrorContext ¶
ErrorContext logs a message at error log level.
func (*Logger) ErrorContextE ¶
ErrorContextE logs a message at error log level with an error stacktrace.
func (*Logger) InfoContext ¶
InfoContext logs a message at info log level.