8 releases

0.1.8 Feb 2, 2021
0.1.7 Feb 2, 2021
0.1.6 Jan 30, 2021
0.1.3 Mar 1, 2020
0.1.0 Jun 30, 2019

#673 in Debugging

Download history 2/week @ 2023-12-19 28/week @ 2023-12-26 2/week @ 2024-01-23 7/week @ 2024-01-30 4/week @ 2024-02-13 19/week @ 2024-02-20 16/week @ 2024-02-27 9/week @ 2024-03-05 29/week @ 2024-03-12 16/week @ 2024-03-19 2/week @ 2024-03-26 18/week @ 2024-04-02

67 downloads per month

Apache-2.0

11KB
209 lines

structlog

If you like to include useful pieces of information in log messages but don't want to use verbose text to join all the pieces together, this crate might get you some way towards that. It won't help you make your messages useful nor will it be the fastest way to get messages into such-and-such system. The primary outflow for these messages is as a JSON serialised structure that just includes the keys and values given to the logger.

This is currently being built to use in another of my projects, so it will be updated and extended as needs arise. Contributions are welcome and encouraged. Please see the Contribution guide to find out how you can help.

Current usage options

You create an Event which implements fmt::Display to output JSON for convenience. There are a few useful fields added when you create the event like a created timestamp and the caller location. Creating an event can either be done using a Event::from_str() like: -


// By default the event will be created with a level/severity of INFO.
let test_event = Event::from_str("some event");

// To make it another level you can do: -
let mut test_event_error = Event::from_str("something bad happened");
test_event_error.error();

or you can use: -

let mut test_event = Event::new();
test_event.add_field(
    String::from("message"),
    String::from("some useful message"),
);

If you println!("{}", test_event) you would see something like: -

{"attributes":{"message":"Some useful message"},"created":"2021-02-02T20:04:06.949823Z","level":"INFO","severity":"INFO","caller":"tests/integration_tests.rs:5:18"}

Dependencies

~1.6–2.6MB
~50K SLoC