Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(appName string)
Init initializes the global logger.
It automatically determines the environment using SWARMCLI_ENV:
- SWARMCLI_ENV=dev → human-readable logs in ~/.local/state/<app>/app-debug.log
- SWARMCLI_ENV=prod → JSON logs in ~/.local/state/<app>/app.log
The log level is controlled via LOG_LEVEL (debug, info, warn, error, etc). If unset, defaults to debug in dev mode and info in prod mode.
func InitSlog ¶
InitSlog installs a logger that forwards everything to h instead of writing a file, so that a program built on log/slog gets this package's output in its own format, on its own stream, at its own level.
It exists for consumers that import swarmcli as a library rather than running the TUI. Init is wrong for them twice over: it opens a lumberjack file under ~/.local/state, which in a container is a file nobody will ever read, and it would put a second format on a stream the host program already owns. Not calling it at all is worse — L() then returns the no-op logger and everything this package's callers report is silently discarded. That was swarmcli-cd#72.
The level is h's. LOG_LEVEL and SetLevel do not apply, because the host program's handler already decides what it keeps and having two answers to that question is how logs go missing.
func InitTestIfTestLogEnv ¶
func InitTestIfTestLogEnv()
InitTestIfTestLogEnv creates a lightweight logger for tests that logs to stdout if the `TEST_LOG` env is set.
Types ¶
type SwarmLogger ¶
type SwarmLogger struct {
*zap.SugaredLogger
}
SwarmLogger wraps zap’s SugaredLogger for convenience.
func (*SwarmLogger) With ¶
func (l *SwarmLogger) With(args ...interface{}) *SwarmLogger
With adds structured fields to the logger and returns a new instance.