swarmlog

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

func InitSlog(h slog.Handler)

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.

func SetLevel

func SetLevel(level zapcore.Level)

SetLevel allows changing the log level at runtime.

func Sync

func Sync()

Sync flushes any buffered log entries.

Types

type SwarmLogger

type SwarmLogger struct {
	*zap.SugaredLogger
}

SwarmLogger wraps zap’s SugaredLogger for convenience.

func L

func L() *SwarmLogger

L returns the global logger or a no-op fallback if uninitialized.

func (*SwarmLogger) With

func (l *SwarmLogger) With(args ...interface{}) *SwarmLogger

With adds structured fields to the logger and returns a new instance.

Jump to

Keyboard shortcuts

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