= Integrate a slog Logger with your Rocket.rs application

This is a fairing that you can attach to your rocket.rs application to enable use of a slog Logger in your handlers

== Installation

In your Cargo.toml, put the following in the [dependencies] section:


rocket-slog = "0.1"

For pre-2018-edition crates, put the following in your crate root:


extern crate rocket_slog;

== Example

Here is an example application that uses the rocket-slog fairing. Note that you should probably disable the builtin rocket logger unless you want the output from both logging systems.


![feature(plugin)]

![plugin(rocket_codegen)]

extern crate rocket; extern crate rocket_slog;

[macrouse(slogo, debug)] extern crate slog;

extern crate slogterm; extern crate slogasync;

use rocket::{State, Config}; use slog::Drain; use rocket_slog::{SyncLogger, SlogFairing};

[get("/")]

fn index(logger: State) -> &'static str { debug!(&**logger, "THIS IS A CUSTOM MESSAGE"); "hello, world" }

fn main() { let decorator = slogterm::TermDecorator::new().build(); let drain = slogterm::FullFormat::new(decorator).build().fuse(); let drain = slogasync::Async::new(drain).build().fuse(); let logger = slog::Logger::root(drain, slogo!("version" => env!("CARGOPKGVERSION")));

let fairing = SlogFairing::new(logger);

let config = Config::development().unwrap();
rocket::custom(config, false) // disables logging
    .attach(fairing)
    .mount("/", routes![index])
    .launch();

}