slog-rs
Code snippet
fn main() {
let root = root_logger!("version" => VERSION);
let _log = child_logger!(root, "child" => 1);
let counter = Arc::new(AtomicUsize::new(0));
let log = child_logger!(root, "counter" => {
let counter = counter.clone();
move || { counter.load(SeqCst)}
});
info!(log, "before-fetch-add"); counter.fetch_add(1, SeqCst);
info!(log, "after-fetch-add");
log.set_drain(
drain::filter_level(
Level::Info,
drain::stream(
std::io::stderr(),
format::Json::new(),
),
),
);
trace!(log, "trace", "lazy-closure" => Box::new(move || slow_fib(40)));
let join = thread::spawn({
let log = log.clone();
move || {
info!(log, "subthread", "stage" => "start");
thread::sleep(Duration::new(1, 0));
info!(log, "subthread", "stage" => "end");
}
});
join.join().unwrap();
}
See examples/features.rs
for full code.
Introduction
Structured, composable logging for Rust. Work in progress, but usable
already.
Heavily inspired by log15 for Go, which I liked so much, that I want it in
Rust too.
Read Documentation for details and features.
If you want to say hi, or need help use #dpc gitter.im.
To report a bug or ask for features use github issues.
Building & running
If you need to install Rust (come on, you should have done that long time ago!), use rustup.
In your project
In Cargo.toml:
[dependencies]
slog = "*"
In your main.rs
:
extern crate slog;