pub struct FileSink { /* private fields */ }Expand description
Per-tag file sink.
§Thread safety
All writes go through a single Mutex. Contention is low because
writes are small and every record is flushed immediately.
Implementations§
Source§impl FileSink
impl FileSink
Sourcepub fn new(log_dir: impl Into<PathBuf>) -> Result<Self>
pub fn new(log_dir: impl Into<PathBuf>) -> Result<Self>
Create a new file sink rooted at log_dir.
Creates the directory (and any missing parents) if it does not already exist.
Sourcepub fn write(&self, record: &LogRecord) -> Result<()>
pub fn write(&self, record: &LogRecord) -> Result<()>
Write one LogRecord to {dir}/{record.tag}.log.
Opens the file in append mode on first use for a given tag; caches the handle thereafter. Serialises the record as a single JSON line, writes it, and flushes.
§Errors
Returns io::Error if the file can’t be opened or written.
The caller (log() in lib.rs) treats this as best-effort and
silently drops the file write on failure.
Auto Trait Implementations§
impl !Freeze for FileSink
impl RefUnwindSafe for FileSink
impl Send for FileSink
impl Sync for FileSink
impl Unpin for FileSink
impl UnsafeUnpin for FileSink
impl UnwindSafe for FileSink
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
Mutably borrows from an owned value. Read more