Configuration
The logger is configured using the `Config` struct.
- Dir
string: Directory for log files. Defaults to./logs. - TerminalOutput
bool: Enables or disables console output. - MinLevel
slog.Level: Minimum level for file logging. Defaults toslog.LevelInfo. - ConsoleMinLevel
slog.Level: Minimum level specifically for console output. If not set, it followsMinLevel. - MaxFileSize
int64: Maximum size per log file before rotation. Defaults to10MB. - MaxLogFiles
int: Maximum number of managed log files to keep. Defaults to5. - DisableColors
bool: Disables ANSI colors in console output. - AddSource
bool: Adds source file and line information to structured log output.
type Config struct {
Dir string
TerminalOutput bool
MinLevel slog.Level
ConsoleMinLevel slog.Level
MaxFileSize int64
MaxLogFiles int
DisableColors bool
AddSource bool
}
Dir
Directory where log files are stored.
If the directory does not exist, it is created automatically during logger initialization.
Default directory:
./logsTerminalOutput
Enables or disables terminal logging. When enabled, logs are written both to files and to the console using a human-readable colored format. Typical usage:
- enabled during local development
- disabled in production containers
MinLevel
Defines the minimum log level written to log files. Example:
MinLevel: slog.LevelInfoThis means:
- INFO
- WARN
- ERROR
are written to files, while lower levels such as DEBUG are ignored.
ConsoleMinLevel
Defines the minimum log level used specifically for terminal output.
This allows terminal logging to be more or less verbose independently of file logging.
Example:
MinLevel: slog.LevelInfo
ConsoleMinLevel: slog.LevelDebugIn this configuration:
- files store only
INFOand above - terminal output also includes
DEBUG
If not set, the console uses the same level as MinLevel.
MaxFileSize
Maximum size of a single log file before automatic rotation occurs.
Example:
MaxFileSize: 10 * 1024 * 1024Default:
10MBWhen the limit is reached, the logger automatically creates a new file.
MaxLogFiles
Maximum number of rotated log files kept on disk.
Older files are removed automatically during cleanup.
Example:
MaxLogFiles: 5DisableColors
Disables ANSI terminal colors.
Useful when:
- logs are redirected to files
- running inside CI pipelines
- terminal does not support ANSI colors
AddSource
Adds source file and line information to log entries.
Example output:
{
"source": {
"function": "main.main",
"file": "/examples/add_source/main.go",
"line": 19
}
}Useful during development and debugging, but may slightly increase logging overhead.
The configuration system is designed to remain fully compatible with Go’s standard log/slog ecosystem while providing production-oriented logging features such as rotation, structured output, and terminal formatting.