MCPcopy Create free account
hub / github.com/GCWing/BitFun / new

Method new

src/apps/cli/src/logging.rs:44–70  ·  view source on GitHub ↗
(
        dir: impl AsRef<Path>,
        file_name: impl Into<String>,
        max_size: u64,
    )

Source from the content-addressed store, hash-verified

42
43impl 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()

Callers

nothing calls this directly

Calls 5

with_extensionMethod · 0.80
rotateMethod · 0.80
remove_old_filesMethod · 0.80
joinMethod · 0.45
open_fileMethod · 0.45

Tested by

no test coverage detected