https://github.com/containerscrew/tiny-tracing
Simple rusty log library (tracing-subscriber wrapper)
https://github.com/containerscrew/tiny-tracing
builder-pattern env-filter json-logger logger logging observability rust rust-crate structured-logging tracing tracing-subscriber
Last synced: 5 days ago
JSON representation
Simple rusty log library (tracing-subscriber wrapper)
- Host: GitHub
- URL: https://github.com/containerscrew/tiny-tracing
- Owner: containerscrew
- License: mit
- Created: 2025-05-11T19:30:08.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2026-07-06T13:30:26.000Z (13 days ago)
- Last Synced: 2026-07-06T15:13:18.521Z (13 days ago)
- Topics: builder-pattern, env-filter, json-logger, logger, logging, observability, rust, rust-crate, structured-logging, tracing, tracing-subscriber
- Language: Rust
- Homepage: https://docs.rs/tiny-tracing
- Size: 129 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Agents: AGENTS.md
Awesome Lists containing this project
README
# 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:
```shell
cargo add tiny-tracing
```
Minimal setup — text output at INFO level, nothing else needed:
```rust
use tiny_tracing::Logger;
fn main() -> Result<(), Box> {
Logger::new().init()?;
tiny_tracing::info!("Application started");
Ok(())
}
```
## Configuration
The builder API exposes every knob through chainable methods:
```rust
use tiny_tracing::{Logger, LogFormat, Level, Output};
fn main() -> Result<(), Box> {
Logger::new()
.with_level(Level::DEBUG) // TRACE | DEBUG | INFO | WARN | ERROR
.with_format(LogFormat::Json) // Text | Json
.with_env_filter("info,my_crate=trace") // per-target EnvFilter, on top of level
.with_file(true) // show source file in log lines
.with_target(false) // hide module path
.with_output(Output::Both("app.log".into())) // stdout + file
.init()?;
Ok(())
}
```
| 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:
```rust
use tiny_tracing::{LogFormat, Level};
let format: LogFormat = "json".parse()?;
let level: Level = "debug".parse()?;
# Ok::<_, Box>(())
```
## Examples
Runnable examples live under [`examples/`](./examples):
```bash
cargo run --example basic # text output at INFO
cargo run --example json # JSON output at DEBUG, with file locations
cargo run --example env_filter # per-target filter (respects RUST_LOG)
cargo run --example file # write to stdout + a file at once
```
## 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) license.
## Development
```bash
git clone https://github.com/containerscrew/tiny-tracing.git
cd tiny-tracing
cargo test # unit + integration + doc-tests
cargo fmt --all -- --check # check formatting
cargo clippy --all-targets --all-features -- -D warnings
```
Releases are automated via [cocogitto](https://docs.cocogitto.io/) (Conventional Commits).
See the [release skill](.claude/skills/release/SKILL.md) for the full workflow.