From 4a6498a6f1d9c2421d485c2f09ec08aa8d830cff Mon Sep 17 00:00:00 2001 From: Jonathan Strong Date: Tue, 13 Feb 2018 00:41:11 -0500 Subject: [PATCH] adds async_file_logger fn --- Cargo.toml | 1 + src/lib.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index cdaa313..9e82ac4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ ordermap = "0.3" fnv = "1" uuid = { version = "0.5", features = ["serde", "v4"] } hdrsample = "6" +slog-async = "2" decimal = { path = "../decimal", version = "2" } diff --git a/src/lib.rs b/src/lib.rs index 65d8975..5d13c4c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ extern crate hyper; extern crate termion; extern crate sloggers; extern crate slog_term; +extern crate slog_async; extern crate fnv; extern crate ordermap; extern crate decimal; @@ -33,6 +34,7 @@ pub use sloggers::types::Severity; use sloggers::types::TimeZone; #[allow(unused_imports)] use sloggers::file::FileLoggerBuilder; +use slog::Drain; pub mod influx; pub mod warnings; @@ -59,6 +61,15 @@ pub fn file_logger(_: &str, _: Severity) -> slog::Logger { Logger::root(Discard, o!()) } +pub fn async_file_logger(path: &str, level: Severity) -> slog::Logger { + let drain = file_logger(path, level); + let async_drain = + slog_async::Async::new(drain) + .chan_size(100_000) + .build(); + slog::Logger::root(async_drain.fuse(), o!()) +} + pub fn dt_nanos(t: DateTime) -> i64 { (t.timestamp() as i64) * 1_000_000_000_i64 + (t.timestamp_subsec_nanos() as i64) }