3 unstable releases

0.2.0 Oct 12, 2019
0.1.1 Oct 22, 2018
0.1.0 Feb 14, 2018

#168 in Debugging

Download history 9142/week @ 2022-01-24 7295/week @ 2022-01-31 4955/week @ 2022-02-07 4765/week @ 2022-02-14 3653/week @ 2022-02-21 4327/week @ 2022-02-28 4148/week @ 2022-03-07 4180/week @ 2022-03-14 4392/week @ 2022-03-21 4033/week @ 2022-03-28 4074/week @ 2022-04-04 2889/week @ 2022-04-11 3553/week @ 2022-04-18 4428/week @ 2022-04-25 4437/week @ 2022-05-02 5947/week @ 2022-05-09

18,539 downloads per month
Used in 2 crates (via silkroad)

MIT/Apache

13KB
132 lines

Slog Derives

Build Status Crates.io Link Online Documentation

Custom derives for use with slog logging.

The KV Derive

Sometimes you'll want to log the struct's contents in your application, for example when you've just started and want to record the configuration details for debugging purposes. Usually you'd need to do something like this:

#[macro_use]
extern crate slog;
use std::path::PathBuf;

struct Config {
    width: f64,
    height: f64,
    url: String,
}

let cfg = Config { ... };

debug!(logger, "Loaded Config";
    "width" => cfg.width,
    "height" => cfg.height,
    "url" => cfg.url);
# }

This is where the KV trait comes in. Implementing it lets you log a type as a bunch of key-value pairs, translating the previous log statement into something like this:

debug!(logger, "Loaded Config"; cfg);

This crate provides a custom derive which will implement KV for you. It'll just iterate over each field in your struct and invoke Value::serialize() on each. You can also use the #[slog(skip)] attribute to skip specific fields.

#[derive(KV)]
pub struct Config {
  width: f64,
  height: f64,
  #[slog(skip)]
  url: String,
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~250–670KB
~16K SLoC