| Crates.io | dyson_log |
| lib.rs | dyson_log |
| version | 0.1.1 |
| created_at | 2025-10-23 17:38:38.94922+00 |
| updated_at | 2025-12-30 07:55:30.38403+00 |
| description | Plug and play logging |
| homepage | https://github.com/TikTzuki/tiktuzki-scripts |
| repository | https://github.com/TikTzuki/tiktuzki-scripts |
| max_upload_size | |
| id | 1897416 |
| size | 41,233 |
Plug-and-play logging for Rust services built on tracing-subscriber with:
Add this to your Cargo.toml:
[dependencies]
dyson_log = "0"
tracing = "0.1" # to use the `info!`, `warn!`, etc. macros
If you're in a workspace using this repo locally, you can depend on it by path while developing:
[dependencies]
dyson_log = { path = "../../crates/dyson_log" }
tracing = "0.1"
Call init_log() once at startup and keep the returned guard alive for the entire process lifetime to ensure logs are flushed.
use tracing::{info, warn};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Initialize logging (honors environment variables below)
let _guard = dyson_log::init_log();
info!("service starting");
// ... your app ...
warn!("service stopping");
Ok(())
}
1ENABLE_LOG=0 to disable logging entirelylogsLOG_PATH=/var/log/myappapp.logLOG_FILE=server.logtracing filter
RUST_LOG=info, RUST_LOG=debug,my_crate=trace,hyper=warntracing_subscriber::EnvFilter::from_default_env()TOKIO_CONSOLE_ENABLE=1Example JSON line (shape will vary):
{
"timestamp":"2025-01-01T12:00:00Z",
"level":"INFO",
"target":"my_app::service",
"message":"service starting",
"span":{"name":"request","id":1},
"line":42
}
RUST_LOG for production to reduce noise while keeping diagnostics when needed.WorkerGuard (from init_log()) in a variable to ensure file logs are flushed on shutdown.tracing spans for rich, contextual logs across async boundaries.Licensed under either of
at your option.