#logging #env-logger #witchcraft #env-var #structured-logging

witchcraft-env-logger

A simple Witchcraft logger that can be configured with an environment variable

3 releases (stable)

Uses new Rust 2024

2.0.0 Sep 23, 2025
2.0.0-rc1 Aug 18, 2025
1.0.0 May 27, 2025

#865 in Debugging

Download history 20/week @ 2025-10-01

155 downloads per month

Apache-2.0

75KB
1.5K SLoC

A simple Witchcraft logger that can be configured with an environment variable.

This is similar to the env_logger crate, but using the witchcraft_log crate instead of the log crate. Configuration of logging levels is the same as env_logger except for the additional fatal log level. Regex filters are not supported.

Logs are written to standard error in the standard Witchcraft service.1 JSON format.

Example

use witchcraft_log::{debug, error, info, Level};

witchcraft_env_logger::init();

debug!("this is a debug message");
error!("this is printed by default");

if witchcraft_log::enabled!(Level::Info) {
    let x = 3 * 4; // expensive computation
    info!("figured out the answer", safe: { answer: x });
}
$ RUST_LOG=error ./main
{"type":"service.1","level":"ERROR","time":"2025-05-26T16:45:59.204677531Z","origin":"main","thread":"main","message":"this is printed by default","safe":true,"params":{"file":"witchcraft-env-logger/examples/main.rs","line":7}}
$ RUST_LOG=info ./main
{"type":"service.1","level":"ERROR","time":"2025-05-26T16:46:31.043928664Z","origin":"main","thread":"main","message":"this is printed by default","safe":true,"params":{"file":"witchcraft-env-logger/examples/main.rs","line":7}}
{"type":"service.1","level":"INFO","time":"2025-05-26T16:46:31.043976765Z","origin":"main","thread":"main","message":"figured out the answer","safe":true,"params":{"answer":12,"file":"witchcraft-env-logger/examples/main.rs","line":11}}
$ RUST_LOG=main=debug ./main
{"type":"service.1","level":"DEBUG","time":"2025-05-26T16:47:04.831643644Z","origin":"main","thread":"main","message":"this is a debug message","safe":true,"params":{"file":"witchcraft-env-logger/examples/main.rs","line":6}}
{"type":"service.1","level":"ERROR","time":"2025-05-26T16:47:04.831691314Z","origin":"main","thread":"main","message":"this is printed by default","safe":true,"params":{"file":"witchcraft-env-logger/examples/main.rs","line":7}}
{"type":"service.1","level":"INFO","time":"2025-05-26T16:47:04.831720469Z","origin":"main","thread":"main","message":"figured out the answer","safe":true,"params":{"answer":12,"file":"witchcraft-env-logger/examples/main.rs","line":11}}

Dependencies

~6.5–9.5MB
~172K SLoC