logging

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package logging configures process-wide structured logging for GoatFlow.

It honours three environment variables (documented in .env.example):

LOG_FORMAT=json|text     — output format (default: text)
LOG_LEVEL=debug|info|warn|error — minimum level for slog (default: info)
LOG_OUTPUT=stdout|<path> — where logs are written (default: stdout).
LOG_FILE_PATH=<path>     — legacy alias: used as the destination when
                           LOG_OUTPUT is unset/empty, so existing
                           deployments keep their log file.

Two log sinks are configured so the whole codebase behaves consistently:

  1. slog — a level-aware JSON or Text handler becomes the default logger (slog.SetDefault), so every slog.* call in the codebase is structured.
  2. stdlib log — legacy log.Printf call sites are routed through a format-aware writer, so they respect the same LOG_FORMAT and LOG_OUTPUT. In JSON mode each line goes through the slog JSON handler, so both kinds of record share one layout ("level":"INFO" etc.). stdlib log carries no level metadata, so its lines are always emitted at INFO; only slog lines are filtered by LOG_LEVEL.

Index

Constants

View Source
const (
	FormatText = "text"
	FormatJSON = "json"
)

Variables

This section is empty.

Functions

func Configure

func Configure() *slog.Logger

Configure sets up slog and the stdlib log package from the environment. It is safe to call more than once (last call wins) and returns the configured slog.Logger for callers that prefer it.

func NormalizeFormat

func NormalizeFormat(v string) string

func ParseLevel

func ParseLevel(v string) slog.Level

func RunCleanupHooks

func RunCleanupHooks()

RunCleanupHooks closes any managed log files. Called from main on exit.

func TestConfigure

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

TestConfigure installs a deterministic sink for unit tests: slog and the stdlib log package write to w exactly as Configure would.

Types

This section is empty.

Jump to

Keyboard shortcuts

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