Documentation
¶
Overview ¶
Package logkit provides structured logging helpers for CLI applications.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Default ¶
Default returns the package-default structured logger configured via environment variables. It is safe for concurrent use.
The env prefix is the app name passed to InitDefault (uppercased); if InitDefault was not called it falls back to the neutral "SYM" prefix:
- {PREFIX}_LOG_LEVEL: debug, info, warn, error (default: warn)
- {PREFIX}_LOG_FORMAT: text (default), json
func InitDefault ¶ added in v0.1.1
func InitDefault(appName string)
InitDefault sets the application name that Default() uses to read its environment configuration. Call it once at program startup, before the first Default() call. It resets any previously constructed default logger so the next Default() call rebuilds it with the new prefix.
For example, InitDefault("symfetch") makes Default() read SYMFETCH_LOG_LEVEL and SYMFETCH_LOG_FORMAT.
func New ¶
New creates a slog.Logger with the specified writer, level and format. Format must be "text" or "json".
func NewFromEnv ¶
NewFromEnv creates a fresh slog.Logger by reading environment variables prefixed with the given appName. For example, NewFromEnv("symfetch") reads SYMFETCH_LOG_LEVEL and SYMFETCH_LOG_FORMAT.
func ReplaceLogger ¶
ReplaceLogger allows tests to swap the default logger. The returned function restores the previous logger.
Types ¶
This section is empty.