Browse Source

sets file_logger to return a noop logger if cfg(test)

master
Jonathan Strong 6 years ago
parent
commit
fa0d5b68fb
1 changed files with 8 additions and 0 deletions
  1. +8
    -0
      src/lib.rs

+ 8
- 0
src/lib.rs View File

@@ -44,6 +44,7 @@ pub fn nanos(t: DateTime<Utc>) -> u64 {
(t.timestamp() as u64) * 1_000_000_000_u64 + (t.timestamp_subsec_nanos() as u64) (t.timestamp() as u64) * 1_000_000_000_u64 + (t.timestamp_subsec_nanos() as u64)
} }


#[cfg(not(test))]
pub fn file_logger(path: &str, level: Severity) -> slog::Logger { pub fn file_logger(path: &str, level: Severity) -> slog::Logger {
let mut builder = FileLoggerBuilder::new(path); let mut builder = FileLoggerBuilder::new(path);
builder.level(level); builder.level(level);
@@ -51,6 +52,13 @@ pub fn file_logger(path: &str, level: Severity) -> slog::Logger {
builder.build().unwrap() builder.build().unwrap()
} }



#[cfg(test)]
pub fn file_logger(path: &str, level: Severity) -> slog::Logger {
use slog::*;
Logger::root(Discard, o!())
}

pub fn dt_nanos(t: DateTime<Utc>) -> i64 { pub fn dt_nanos(t: DateTime<Utc>) -> i64 {
(t.timestamp() as i64) * 1_000_000_000_i64 + (t.timestamp_subsec_nanos() as i64) (t.timestamp() as i64) * 1_000_000_000_i64 + (t.timestamp_subsec_nanos() as i64)
} }


Loading…
Cancel
Save