pub struct RollingFileWriter { /* private fields */ }Expand description
A log file writer that rolls over to a new file once the current one reaches a maximum size.
Rolled files use Debian-style names: the active file is path, the most recently rolled file is path.1, and the
oldest is path.N, where N is the maximum number of rolled files to keep. Rolling over deletes path.N, renames
each remaining file to the next number up, and starts a new, empty path.
The size check happens before each write, and a write is never split across files: once the file reaches the maximum size, the next write rolls it over first. A file can therefore exceed the maximum size by up to one write.
An existing file at path is appended to, and its size counts towards the maximum once the file is open (see
new for when that is).
If rolling over fails, a warning is printed to standard error and writing continues at path. When path itself
couldn’t be renamed, writing continues in the same file. Otherwise, the renames that succeeded stay in place and a new
file is started, so a rolled file whose own rename failed can be replaced by the one below it.
Implementations§
Source§impl RollingFileWriter
impl RollingFileWriter
Sourcepub fn new(path: impl Into<PathBuf>, max_size: u64, max_rolls: usize) -> Self
pub fn new(path: impl Into<PathBuf>, max_size: u64, max_rolls: usize) -> Self
Creates a new RollingFileWriter for the given path.
The file, and any missing parent directories, are created on the first write. max_size is in bytes.
max_rolls is the number of rolled files to keep, where 0 is treated as 1.
Because the file isn’t open yet, the first write is appended to an existing file without checking its size, and
the size counts from the second write on. Use open to count it before the first write.
Trait Implementations§
Source§impl Write for RollingFileWriter
impl Write for RollingFileWriter
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Auto Trait Implementations§
impl Freeze for RollingFileWriter
impl RefUnwindSafe for RollingFileWriter
impl Send for RollingFileWriter
impl Sync for RollingFileWriter
impl Unpin for RollingFileWriter
impl UnsafeUnpin for RollingFileWriter
impl UnwindSafe for RollingFileWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Track for T
impl<T> Track for T
Source§fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self> ⓘ
fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self> ⓘ
Tracked wrapper. Read more