Logging
What it is
- SnelDB uses the
tracingecosystem for structured, leveled logs. - Logs are emitted to stdout and to a daily‑rotated file, with independent levels.
- Levels and output directory are configured via the config file.
Core pieces
- Initializer — sets up
tracing_subscriberlayers for stdout and file. - Config —
[logging]section controlslog_dir,stdout_level, andfile_level. - Levels —
error,warn,info,debug,trace.
How it works
-
Startup
logging::init()is called frommain.rsbefore starting frontends.- Reads
CONFIG.loggingto build filters and writers. - Installs two layers: ANSI stdout and file appender (
sneldb.log, daily rotation).
-
Emitting logs
- Use
tracing::{error!, warn!, info!, debug!, trace!}in code. - Prefer spans (e.g.,
#[instrument]) to capture context around operations.
- Use
Configuration
Example snippet from config.toml:
[logging]
log_dir = "../data/logs"
stdout_level = "debug"
file_level = "error"
stdout_level: global level for console logs.file_level: global level for file logs.log_dir: directory wheresneldb.logis created (daily rotation).
Why this design
- Structured logs with levels and spans ease debugging and operations.
- Separate stdout/file control supports local development and production hygiene.
Operational notes
- Tune levels per environment (e.g.,
stdout_level=warnin prod). - Ensure
log_direxists and is writable; it is created on first write by the appender. - Use targets when necessary to scope logs for noisy modules.
Further Reading
tracingcrate docstracing_subscriberfilters and formatters