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 |
#94 in #log-messages
255 downloads per month
8KB
96 lines
json_logger
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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