1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use super::slog;
use super::slog_async;
use super::slog_json;
use super::slog_term;
use super::slog::Drain;
pub static APPNAME: &str = "dbui";
#[derive(Clone, Debug)]
pub struct AppConfig {
pub cfg_dir: String,
pub port: i32,
pub verbose: bool,
pub root_logger: slog::Logger
}
pub fn root_logger() -> slog::Logger {
let file = std::fs::OpenOptions::new().create(true).write(true).truncate(true).open("log/server.log").unwrap();
let decorator = slog_term::TermDecorator::new().build();
let d1 = slog_term::FullFormat::new(decorator).build().fuse();
let d2 = slog_json::Json::default(file).fuse();
let both = std::sync::Mutex::new(slog::Duplicate::new(d1, d2)).fuse();
let both = slog_async::Async::new(both)
.build()
.fuse();
slog::Logger::root(both, slog::o!("version" => env!("CARGO_PKG_VERSION")))
}