-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With rotation options: Hourly, Daily, Weekly, Monthly, Yearly. And timestamp from yesterday, hour before, or now. Add test to rotate by date.
- Loading branch information
1 parent
eeafc74
commit cf713f7
Showing
6 changed files
with
285 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Cargo.lock | ||
logs/ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use file_rotate::{ | ||
compression::Compression, | ||
suffix::{AppendTimestamp, DateFrom, FileLimit}, | ||
ContentLimit, FileRotate, TimeFrequency, | ||
}; | ||
use std::io::Write; | ||
|
||
fn main() { | ||
let mut log = FileRotate::new( | ||
"logs/log", | ||
AppendTimestamp::with_format("%Y-%m-%d", FileLimit::MaxFiles(7), DateFrom::DateYesterday), | ||
ContentLimit::Time(TimeFrequency::Daily), | ||
Compression::None, | ||
); | ||
|
||
// Write a bunch of lines | ||
writeln!(log, "Line 1: Hello World!").expect("write log"); | ||
for idx in 2..=10 { | ||
std::thread::sleep(std::time::Duration::from_millis(500)); | ||
writeln!(log, "Line {}", idx).expect("write log"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.