= Integrate a slog Logger with your Rocket.rs application
http://pwoolcoc.gitlab.io/rocket-slog-fairing/rocket_slog/index.html[Documentation (master)]
This is a fairing that you can attach to your rocket.rs application to enable use of a slog Logger
in your
handlers
== Installation (for rocket v0.3)
In your Cargo.toml
, put the following in the [dependencies]
section:
For pre-2018-edition crates, put the following in your crate root:
== Installation (for rocket 0.4)
In your Cargo.toml
, put the following in the [dependencies]
section:
For pre-2018-edition crates, put the following in your crate root:
== Example (for rocket 0.3)
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.
extern crate rocket; extern crate rocket_slog;
extern crate sloggers;
use std::error::Error; use rocket::{Config}; use rocket_slog::{SyncLogger, SlogFairing}; use sloggers::{ Build, terminal::{ TerminalLoggerBuilder, Destination, }, types::Severity, };
fn index(logger: SyncLogger) -> &'static str { debug!(logger.get(), "THIS IS A CUSTOM MESSAGE"); "hello, world" }
fn main() -> Result<(), Box
let fairing = SlogFairing::new(logger);
let config = Config::development().unwrap();
rocket::custom(config, false) // disables logging
.attach(fairing)
.mount("/", routes![index])
.launch();
Ok(())
== Example (for rocket 0.4)
extern crate rocket_slog; extern crate sloggers;
use std::error::Error; use rocket::config::{Config, Environment, LoggingLevel}; use rocket_slog::{SlogFairing, SyncLogger}; use sloggers::{ Build, terminal::{ TerminalLoggerBuilder, Destination, }, types::Severity, };
fn index(log: SyncLogger) -> &'static str { debug!(log, "some log message"); "Hello world" }
fn main() -> Result<(), Box