diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-03-10 20:51:26 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-03-10 20:51:26 +0100 |
commit | 6f329557aff3c7810699bf1bafa0a073798e1b9f (patch) | |
tree | 256d152bd7161085264675851ca81d991917f0f2 /src/config.rs | |
parent | ed24f917ffabfead27d8b5899e29b55eff2810cc (diff) |
feat: add logging with slog
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs index 7146a0b..e6cd0bd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,9 @@ pub use config::ConfigError; +use deadpool_postgres::Pool; use serde::Deserialize; +use slog::{o, Drain, Logger}; +use slog_async; +use slog_term; #[derive(Deserialize)] pub struct ServerConfig { @@ -19,4 +23,18 @@ impl Config { cfg.merge(config::Environment::new())?; cfg.try_into() } + + pub fn logging() -> Logger { + let decorator = slog_term::TermDecorator::new().build(); + let drain = slog_term::FullFormat::new(decorator).build().fuse(); + let drain = slog_async::Async::new(drain).build().fuse(); + + slog::Logger::root(drain, o!()) + } +} + +#[derive(Clone)] +pub struct AppState { + pub pool: Pool, + pub log: slog::Logger, } |