Skip to content

Commit

Permalink
Merge branch 'alboyer-fix_custom_timestamp_format'
Browse files Browse the repository at this point in the history
  • Loading branch information
emabee committed Oct 21, 2024
2 parents 7bc6c91 + 8b3465c commit 9d7fb6c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions examples/rotate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use flexi_logger::{
Age, Cleanup, Criterion, Duplicate, FileSpec, FlexiLoggerError, LevelFilter, Logger, Naming,
};
use std::{thread::sleep, time::Duration};

fn main() -> Result<(), FlexiLoggerError> {
Logger::with(LevelFilter::Info)
.rotate(
Criterion::Age(Age::Second),
Naming::TimestampsCustomFormat {
current_infix: None,
format: "%Y%m%d_%H%M%S",
},
Cleanup::Never,
)
.log_to_file(FileSpec::default())
.duplicate_to_stdout(Duplicate::All)
.start()?;

log::info!("start");
for step in 0..10 {
log::info!("step {}", step);
sleep(Duration::from_millis(250));
}
log::info!("done");

Ok(())
}
2 changes: 1 addition & 1 deletion src/writers/file_log_writer/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ impl State {
} else {
*ts = Local::now();
self.config.file_spec.collision_free_infix_for_rotated_file(
&infix_from_timestamp(ts, self.config.use_utc, &InfixFormat::Std),
&infix_from_timestamp(ts, self.config.use_utc, fmt),
)
}
}
Expand Down

0 comments on commit 9d7fb6c

Please sign in to comment.