tracing-subscriber-multi 0.1.0

Configure multiple log destinations for tracing_subscriber.
Documentation
use std::{io::Write, path::Path};

pub use file_rotate::{
    compression::Compression,
    suffix::{AppendCount, AppendTimestamp},
    ContentLimit,
};
use file_rotate::{suffix::SuffixScheme, FileRotate};

/// A rotating log file. This will create log files that are limited in size,
/// before being moved to `name.X` and optionally compressed.
pub struct RotatingFile<S: SuffixScheme> {
    inner: FileRotate<S>,
}

impl<S: SuffixScheme> RotatingFile<S> {
    /// Create a new rotating file writer
    pub fn new<P>(
        path: P,
        suffix_scheme: S,
        content_limit: ContentLimit,
        compression: Compression,
    ) -> Self
    where
        P: AsRef<Path>,
    {
        Self {
            inner: FileRotate::new(
                path,
                suffix_scheme,
                content_limit,
                compression,
                #[cfg(unix)]
                None,
            ),
        }
    }
}

impl<S: SuffixScheme> Write for RotatingFile<S> {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        self.inner.write(buf)
    }

    fn flush(&mut self) -> std::io::Result<()> {
        self.inner.flush()
    }
}