Skip to content

Logging

Lakta provides two logging modules that work together: tint for formatting and slog for the standard library logger.

lakta.NewRuntime(
config.NewModule(
config.WithConfigDirs(".", "./config"),
config.WithArgs(os.Args[1:]),
),
tint.NewModule(), // provides slog.Handler
slog.NewModule(), // provides *slog.Logger
)

pkg/logging/tint wraps github.com/lmittmann/tint to produce colorized, human-readable console output.

Config path: modules.logging.tint.<name>

time_format string default: 2006-01-02T15:04:05Z07:00

timeFormat specifies the format for timestamping log entries

env LAKTA_MODULES_LOGGING_TINT_<NAME>_TIME_FORMAT

These options can only be set in Go code via With*() functions, not via config files or environment variables.

OptionTypeDescription
WithWriter(...)io.Writersets the output writer (code-only, cannot be configured via files)

pkg/logging/slog registers *slog.Logger in DI and sets it as the global default via slog.SetDefault.

Config path: modules.logging.slog.<name>

level string default: info

level represents the default log level to be used in the configuration

env LAKTA_MODULES_LOGGING_SLOG_<NAME>_LEVEL
levels map[string]string

levels defines a map of per-package log level overrides

env LAKTA_MODULES_LOGGING_SLOG_<NAME>_LEVELS
global_default bool default: true

globalDefault indicates whether the logger should be set as the default globally

env LAKTA_MODULES_LOGGING_SLOG_<NAME>_GLOBAL_DEFAULT

Use github.com/Vilsol/slox to log with the context-carried logger:

slox.Info(ctx, "request received", slog.String("path", r.URL.Path))
slox.Error(ctx, "query failed", slog.Any("err", err))

This ensures log records carry the correct logger (including any fields injected by middleware).