LoggerTerminal Output
Separate Log Levels
The logger supports independent log levels for file output and terminal output.
This allows applications to store stable production logs in files while showing more detailed information in the console during development or debugging sessions.
Configuration is controlled through:
MinLevelConsoleMinLevel
Example configuration:
package main
import (
"log/slog"
"github.com/netlifeguru/logger"
)
func main() {
closer, err := logger.Init(logger.Config{
TerminalOutput: true,
MinLevel: slog.LevelInfo,
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")
}In this configuration:
- log files store:
- INFO
- WARN
- ERROR
- terminal output displays:
- DEBUG
- INFO
- WARN
- ERROR
Example terminal output:
2026-05-11 11:42:18 DBG debug message
2026-05-11 11:42:18 INF application started
2026-05-11 11:42:18 WRN warning messageExample file output:
{
"time": "2026-05-11T11:42:18.102391+02:00",
"level": "INFO",
"msg": "application started"
}If ConsoleMinLevel is not specified, terminal output automatically uses the same level as MinLevel.
This separation is especially useful for:
- local debugging
- development environments
- production observability
- reducing noise in persisted logs