Browse Source

adds `pub fn rotating_file_logger<P>(path: P, level: Severity, compress: bool) -> slog::Logger`

allows optional compression on rotated logfiles
master
Jonathan Strong 5 years ago
parent
commit
7a0684371f
2 changed files with 6 additions and 2 deletions
  1. +1
    -1
      Cargo.toml
  2. +5
    -1
      src/lib.rs

+ 1
- 1
Cargo.toml View File

@@ -1,6 +1,6 @@
[package]
name = "logging"
version = "0.5.1"
version = "0.5.2"
authors = ["Jonathan Strong <jonathan.strong@gmail.com>"]
edition = "2018"



+ 5
- 1
src/lib.rs View File

@@ -65,13 +65,17 @@ pub fn inanos(t: DateTime<Utc>) -> i64 {

//#[cfg(not(any(test, feature = "test")))]
pub fn file_logger<P: AsRef<std::path::Path>>(path: P, level: Severity) -> slog::Logger {
rotating_file_logger(path, level, true)
}

pub fn rotating_file_logger<P: AsRef<std::path::Path>>(path: P, level: Severity, compress: bool) -> slog::Logger {
let mut builder = FileLoggerBuilder::new(path);
builder.level(level)
.timezone(TimeZone::Utc)
.channel_size(CHANNEL_SIZE)
.rotate_size(1024 * 1024 * 1024)
.rotate_keep(1000)
.rotate_compress(true)
.rotate_compress(compress)
.source_location(sloggers::types::SourceLocation::ModuleAndLine);
builder.build().unwrap() // the sloggers impl can't actually fail (v0.3)
}


Loading…
Cancel
Save