This repository has been archived by the owner on Jan 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
92 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use rocket::config::Config; | ||
use rocket::request::{self, FromRequest}; | ||
use rocket::{Outcome, Request, State}; | ||
use slog; | ||
use slog::Drain; | ||
use slog_async; | ||
use slog_scope; | ||
use slog_stdlog; | ||
use slog_term; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct RBLogger { | ||
pub log: slog::Logger, | ||
} | ||
|
||
impl RBLogger { | ||
pub fn new(config: &Config) -> RBLogger { | ||
let decorator = slog_term::TermDecorator::new().build(); | ||
let drain = slog_term::CompactFormat::new(decorator).build().fuse(); | ||
let drain = slog_async::Async::new(drain).build().fuse(); | ||
|
||
RBLogger { | ||
log: slog::Logger::root(drain, o!()).new(o!()), | ||
} | ||
} | ||
} | ||
|
||
impl<'a, 'r> FromRequest<'a, 'r> for RBLogger { | ||
type Error = (); | ||
|
||
fn from_request(req: &'a Request<'r>) -> request::Outcome<Self, ()> { | ||
Outcome::Success(req.guard::<State<RBLogger>>().unwrap().inner().clone()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters