LoggerTerminal Output
Colorized Terminal Output
The logger supports human-readable colored terminal output designed for local development and debugging.
When terminal output is enabled, log entries are printed using ANSI colors based on the log level, making it easier to visually distinguish informational messages, warnings, notices, and errors during runtime.
Enable terminal logging through the TerminalOutput configuration option:
package main
import (
"log/slog"
"github.com/netlifeguru/logger"
)
func main() {
closer, err := logger.Init(logger.Config{
TerminalOutput: true,
ConsoleMinLevel: slog.LevelDebug,
})
if err != nil {
slog.Error(err.Error())
}
defer closer.Close()
slog.Debug("debug message")
slog.Info("application started")
slog.Warn("warning message")
slog.Error("error message")
}Example terminal output:
2026-05-11 12:18:13 [DEBUG] debug message
2026-05-11 12:18:13 [INFO] application started
2026-05-11 12:18:13 [WARN] warning message
2026-05-11 12:18:13 [ERROR] error messageTerminal logging is typically enabled during development while production environments primarily rely on structured JSON log files.
Colors can be disabled using:
DisableColors: trueExample file output:
{"time":"2026-05-11T12:18:13.367992+02:00","level":"INFO","msg":"application started"}
{"time":"2026-05-11T12:18:13.368261+02:00","level":"WARN","msg":"warning message"}
{"time":"2026-05-11T12:18:13.36828+02:00","level":"ERROR","msg":"error message"}This is useful when:
- logs are redirected to files
- running inside CI environments
- terminal output does not support ANSI colors