Skip to content

Commit

Permalink
src: logger: Sync with current tracing-appender crate
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulTrombin authored and joaoantoniocardoso committed Sep 11, 2024
1 parent ac44a7f commit f2971a0
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/logger/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ pub fn init() {
};

let dir = cli::manager::log_path();
let file_appender = tracing_appender::rolling::hourly(dir, "ping-viewer.", ".log");
let file_appender = custom_rolling_appender(
dir,
tracing_appender::rolling::Rotation::HOURLY,
"ping-viewer",
"log",
);
let file_layer = fmt::Layer::new()
.with_writer(file_appender)
.with_ansi(false)
Expand Down Expand Up @@ -116,3 +121,18 @@ pub fn init() {
cli::manager::command_line()
);
}

// Exclusive to output log-file with 'ping-viewer.2024-09-10-18.log' format.
fn custom_rolling_appender<P: AsRef<std::path::Path>>(
dir: P,
rotation: tracing_appender::rolling::Rotation,
prefix: &str,
suffix: &str,
) -> tracing_appender::rolling::RollingFileAppender {
tracing_appender::rolling::RollingFileAppender::builder()
.rotation(rotation)
.filename_prefix(prefix)
.filename_suffix(suffix)
.build(dir)
.expect("failed to initialize rolling file appender")
}

0 comments on commit f2971a0

Please sign in to comment.