[][src]Crate json_logger

JSON Logger

This logger follows the Bunyan logging format.

Example

This example is not tested
#[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());
}

Structs

JsonLogger

Functions

init