diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-15 00:51:21 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-15 00:51:21 -0700 |
commit | 4c90242579c1e673ae47d63786503370c512f148 (patch) | |
tree | dee5e78d8ed1c750b4d8c9c25c4bef9a673c3ca2 /rust/src/bin | |
parent | 28978964a77e853031874230c2415b1b835e93fc (diff) | |
download | fatcat-4c90242579c1e673ae47d63786503370c512f148.tar.gz fatcat-4c90242579c1e673ae47d63786503370c512f148.zip |
add basic slog logging
Diffstat (limited to 'rust/src/bin')
-rw-r--r-- | rust/src/bin/fatcat-iron.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/rust/src/bin/fatcat-iron.rs b/rust/src/bin/fatcat-iron.rs index 4c168981..eed98b1d 100644 --- a/rust/src/bin/fatcat-iron.rs +++ b/rust/src/bin/fatcat-iron.rs @@ -6,10 +6,17 @@ extern crate fatcat; extern crate fatcat_api; extern crate futures; extern crate iron; +extern crate iron_slog; extern crate swagger; #[macro_use] extern crate error_chain; +#[macro_use] +extern crate slog; +extern crate slog_term; +extern crate slog_async; +use slog::{Drain, Logger}; +use iron_slog::{LoggerMiddleware, DefaultLogFormatter}; use clap::{App, Arg}; use iron::{Chain, Iron}; use swagger::auth::AllowAllMiddleware; @@ -25,10 +32,19 @@ fn main() { ) .get_matches(); + + 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(); + let logger = Logger::root(drain, o!()); + let formatter = DefaultLogFormatter; + let server = fatcat::server().unwrap(); let router = fatcat_api::router(server); - let mut chain = Chain::new(router); + let mut chain = Chain::new( + LoggerMiddleware::new(router, logger, formatter )); + chain.link_before(fatcat_api::server::ExtractAuthData); // add authentication middlewares into the chain here // for the purpose of this example, pretend we have authenticated a user |