What do I need?
Rust 1.88.0 or newer: rlg's declared minimum supported Rust version, which CI builds every library and binary on. rlg uses the 2024 edition. The native sinks need macOS or Linux; elsewhere, including Windows, rlg writes to standard output.
How do I add it?
or in Cargo.toml:
[dependencies]
rlg = "0.0.15"
No Cargo features are on by default.
How do I write a record?
use Log;
use LogFormat;
Log::info starts a record; Log::trace, debug, verbose, warn, error, fatal and critical start one at another level. .with adds an attribute of any type that serialises to JSON, and .fire() hands the record to the background thread.
Where does the record go?
To the platform's log. On macOS, read it with log show --last 1m; on Linux, with journalctl -t rlg. To see records on standard output while you work, set RLG_FALLBACK_STDOUT=1:
RLG_FALLBACK_STDOUT=1
The caller attribute records the file and line that called fire().
How do I set the level and the default format?
Use the builder instead of rlg::init():
use LogFormat;
use LogLevel;
let _guard = builder
.level
.format
.init
.expect;
The builder's format applies to records from the log facade; without one, they are logfmt on a terminal and JSON in a pipe or a file. A record you build yourself keeps the format you give it, and is written as MCP if you give none. RUST_LOG=debug sets the level without a code change.
Do my log and tracing calls still work?
Yes. rlg::init() installs rlg behind the log facade and as the tracing subscriber, so existing log::warn! and tracing::info! calls are written through rlg too.
Where next?
- The API guide for levels, formats, configuration and Cargo features.
- The migration guide if you are coming from
log,slogortracing. - The user manual and the API reference on docs.rs.