logkit

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

func Default() *slog.Logger

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

func New(w io.Writer, level slog.Level, format string) *slog.Logger

New creates a slog.Logger with the specified writer, level and format. Format must be "text" or "json".

func NewFromEnv

func NewFromEnv(appName string) *slog.Logger

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

func ReplaceLogger(l *slog.Logger) func()

ReplaceLogger allows tests to swap the default logger. The returned function restores the previous logger.

Types

This section is empty.

Jump to

Keyboard shortcuts

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