tiny-tracing
A lightweight, builder-style logging library for Rust that wraps tracing and
tracing-subscriber. Designed for small to medium projects that want structured or
plain-text output with zero fuss.
Quickstart
Add the crate to your project:
cargo add tiny-tracing
Minimal setup — text output at INFO level, nothing else needed:
use Logger;
Configuration
The builder API exposes every knob through chainable methods:
use ;
| Method | Default | Description |
|---|---|---|
with_level(Level::DEBUG) |
Level::INFO |
Global log level (tracing::Level); with_env_filter refines it per-target |
with_format(LogFormat::Json) |
LogFormat::Text |
Output format |
with_env_filter("info,my_crate=debug") |
none | Per-target filter via EnvFilter, layered on the level |
with_file(true) |
false |
Show source file path in log lines |
with_target(false) |
true |
Show module path in log lines |
with_output(Output::Both("app.log".into())) |
Output::Stdout |
Write to stdout, a file, or both |
Output destinations
with_output takes an Output: Stdout (default), File(path), or Both(path).
File output is opened in append mode (created if missing) with synchronised,
blocking writes — no background thread, no guard to keep alive. ANSI colours are
kept on stdout but stripped from the file, so the on-disk log stays clean.
Need to load config from a string (env var, TOML)? LogFormat implements FromStr,
and tracing::Level does too:
use ;
let format: LogFormat = "json".parse?;
let level: Level = "debug".parse?;
# Ok::
Examples
Runnable examples live under examples/:
Safety
The library calls tracing_subscriber::try_init() internally — calling init() more
than once returns a LoggerError::TryInitError instead of panicking. No unsafe code
anywhere in the crate.
License
tiny-tracing is distributed under the terms of the MIT license.
Development
Releases are automated via cocogitto (Conventional Commits). See the release skill for the full workflow.