Skip to content

Commit

Permalink
log rotation: limit to 3 hour of logs
Browse files Browse the repository at this point in the history
* changed logging directory to /tmp
  • Loading branch information
svenrademakers committed Apr 8, 2024
1 parent 62ed624 commit a3ae851
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use std::{
use tracing::level_filters::LevelFilter;
use tracing::Level;
use tracing_appender::non_blocking::WorkerGuard;
use tracing_appender::rolling::Rotation;
use tracing_subscriber::filter::Targets;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
Expand Down Expand Up @@ -133,7 +134,13 @@ async fn redirect(request: HttpRequest, port: web::Data<u16>) -> HttpResponse {
}

fn init_logger() -> WorkerGuard {
let file_appender = tracing_appender::rolling::hourly("/var/log/bmcd", "bmcd.log");
let file_appender = tracing_appender::rolling::Builder::new()
.rotation(Rotation::HOURLY)
.max_log_files(3)
.filename_prefix("bmcd.log")
.build(std::env::temp_dir())
.expect("error setting up log rotation");

let (bmcd_log, guard) = tracing_appender::non_blocking(file_appender);
let full_layer = tracing_subscriber::fmt::layer().with_writer(bmcd_log);

Expand Down

0 comments on commit a3ae851

Please sign in to comment.