Introduction: This guide explains how to control lazydns logging via configuration file, environment variables, or command line.
The log section in the config file supports:
level: trace|debug|info|warn|error - Default log level for lazydnsconsole: true|false - Whether to output logs to console/stdout (default: false)format: text (default) or json - Output format (json outputs structured logs)file: File logging configuration (optional)
enabled: true|false - Whether file logging is enabled (default: false)path: Path to the log filerotation: Rotation policy configuration
type: time|size|both|never - Rotation trigger typeperiod: daily|hourly|never - Time period for rotation (for time/both)max_size: Maximum file size in bytes before rotation (for size/both)max_files: Number of rotated files to keep (for size/both)compress: Whether to compress rotated files (reserved for future use)Rotates logs based on time periods using local timezone.
log:
level: info
file:
enabled: true
path: /var/log/lazydns/app.log
rotation:
type: time
period: daily # or 'hourly'
Generated filenames: app.log.2026-01-09, app.log.2026-01-08, etc.
Rotates logs when file exceeds a size limit with numbered backups.
log:
level: info
file:
enabled: true
path: /var/log/lazydns/app.log
rotation:
type: size
max_size: 10M # 10MB in bytes
max_files: 5 # Keep 5 rotated files
Generated filenames: app.log, app.log.1, app.log.2, …, app.log.5
Rotates on whichever trigger fires first - useful for high-traffic scenarios.
log:
level: info
file:
enabled: true
path: /var/log/lazydns/app.log
rotation:
type: both
period: daily # Rotate daily
max_size: 10M # OR when file exceeds 10MB
max_files: 5 # Keep 5 size-rotated files
Append to a single file without rotation.
log:
level: info
file:
enabled: true
path: /var/log/lazydns/app.log
rotation:
type: never
Log level is determined by (in order of priority):
RUST_LOG - If set and non-empty, used verbatim-v flags (when RUST_LOG not set):
-v: use warn,lazydns=<config.level> (external crates stay quiet)-v: set lazydns to debug-vv: set lazydns to trace-vvv or more: global trace (includes external crates)levelThe following environment variables can override config settings:
| Variable | Description | Example |
|---|---|---|
RUST_LOG |
Full log specification | RUST_LOG=trace |
LOG_LEVEL |
Log level | LOG_LEVEL=debug |
LOG_FORMAT |
Output format | LOG_FORMAT=json |
LOG_FILE |
Enable file logging with path | LOG_FILE=/var/log/app.log |
LOG_CONSOLE |
Console output | LOG_CONSOLE=false |
log:
# Log level: trace, debug, info, warn, error
level: info
# Output to console (default: false)
console: true
# Output format: text or json
format: text
# File logging configuration
file:
# Enable file logging (default: false)
enabled: true
# Path to log file
path: /var/log/lazydns/lazydns.log
# Rotation configuration
rotation:
# Rotation type: time, size, both, or never
type: both
# Time period: daily or hourly (for type: time or both)
period: daily
# Max file size in bytes (for type: size or both)
max_size: 10M # 10MB
# Number of rotated files to keep (for type: size or both)
max_files: 5
# Compress rotated files (future feature)
compress: false
# Override all logs with environment variable
RUST_LOG=trace ./lazydns
# Increase verbosity with CLI flags
./lazydns -v # lazydns shows debug
./lazydns -vv # lazydns shows trace
./lazydns -vvv # all crates show trace
# Combine environment overrides
LOG_LEVEL=debug LOG_FILE=/tmp/debug.log ./lazydns
| Issue | Solution |
|---|---|
Configured file but no logs in file |
Ensure file.enabled: true and binary built with log-file feature |
| Incorrect time in logs | Check host timezone and local offset availability |
Invalid RUST_LOG value |
Falls back to warn,lazydns=<config.level> with warning |
| No logs shown | Ensure log level not set too high; try lowering level via env or CLI |
| Rotation not working | Check rotation.type is not never and file permissions are correct |
The log-file feature must be enabled for file logging support. Without it, file configuration is ignored and a warning is logged.
# Cargo.toml
[dependencies]
lazydns = { version = "0.2", features = ["log-file"] }
The logging module is designed to be potentially extractable as a standalone crate (lazylog) for reuse in other projects. Key components:
RotationTrigger - Serde-compatible rotation policy enumRotationPeriod - Time period enum (daily/hourly/never)RotatingWriter - Implements std::io::Write with rotation supporttracing-subscriber via tracing_appender::non_blocking