Crate json_logger [−] [src]

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::LogLevelFilter;
use rustc_serialize::json;

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

fn main() {
    json_logger::init("app_name", LogLevelFilter::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());
}

Structs

JsonLogger

Functions

init