3 unstable releases

Uses old Rust 2015

0.1.0 Jan 17, 2019
0.0.2 Jun 27, 2018
0.0.1 May 4, 2015

#1325 in Encoding

Download history 81/week @ 2023-11-20 47/week @ 2023-11-27 100/week @ 2023-12-04 144/week @ 2023-12-11 100/week @ 2023-12-18 117/week @ 2023-12-25 76/week @ 2024-01-01 124/week @ 2024-01-08 53/week @ 2024-01-15 111/week @ 2024-01-22 85/week @ 2024-01-29 84/week @ 2024-02-05 72/week @ 2024-02-12 292/week @ 2024-02-19 82/week @ 2024-02-26 144/week @ 2024-03-04

592 downloads per month

MIT/Apache

8KB
96 lines

json_logger

Build Status

Documentation

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.


lib.rs:

JSON Logger

This logger follows the Bunyan logging format.

Example

#[macro_use] extern crate log;
extern crate json_logger;
extern crate rustc_serialize;

use log::LevelFilter;
use rustc_serialize::json;

#[derive(RustcEncodable)]
struct LogMessage<'a> {
    msg: &'a str,
    event: &'a str
}

fn main() {
    json_logger::init("app_name", LevelFilter::Info).unwrap();

    // This string will show up in the "msg" property
    info!("sample message");

    // This will extend the log message JSON with additional properties
    info!("{}", json::encode(&LogMessage {
        msg: "sample message 2", event: "structured log"
    }).unwrap());
}

Dependencies

~0.9–1.3MB
~21K SLoC