Skip to content

Commit

Permalink
Fix custom timestamp format
Browse files Browse the repository at this point in the history
- Use provided format when computing infix from timestamp.
- Add new rotate example.
  • Loading branch information
alboyer committed Oct 19, 2024
1 parent 7bc6c91 commit 8b3465c
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 8b3465c

Please sign in to comment.