(
dir: impl AsRef<Path>,
file_name: impl Into<String>,
max_size: u64,
)
| 42 | |
| 43 | impl RotatingFile { |
| 44 | fn new( |
| 45 | dir: impl AsRef<Path>, |
| 46 | file_name: impl Into<String>, |
| 47 | max_size: u64, |
| 48 | ) -> std::io::Result<Self> { |
| 49 | let dir = dir.as_ref().to_path_buf(); |
| 50 | let file_name = file_name.into(); |
| 51 | let path = dir.join(&file_name).with_extension("log"); |
| 52 | |
| 53 | let mut rotator = Self { |
| 54 | dir, |
| 55 | file_name, |
| 56 | path, |
| 57 | max_size, |
| 58 | current_size: 0, |
| 59 | inner: None, |
| 60 | buffer: Vec::new(), |
| 61 | }; |
| 62 | |
| 63 | rotator.open_file()?; |
| 64 | if rotator.current_size >= rotator.max_size { |
| 65 | rotator.rotate()?; |
| 66 | } |
| 67 | rotator.remove_old_files(ROTATED_LOG_KEEP_COUNT)?; |
| 68 | |
| 69 | Ok(rotator) |
| 70 | } |
| 71 | |
| 72 | fn open_file(&mut self) -> std::io::Result<()> { |
| 73 | let file = OpenOptions::new() |
nothing calls this directly
no test coverage detected