[−][src]Struct poly_logger::FileLogger
Implements a GenLogger that outputs to File
Simple Example
Instantiates a logger with default message and timestamp format and log file written in 'append' mode (as opposed to truncating first).
use log::info; use log::LevelFilter; use poly_logger::FileLogger; // Currently it is mandatory to set the filename, but I may // introduce a default where an auto-named file is created // in the current directory let mut logger = FileLogger::new(LevelFilter::Info); logger.filename("./test.log"); logger.init().unwrap(); info!("This is an INFO message");
Customized Example
Instantiates a logger with custom timestamp and message format. We are also setting the truncate flag so that log file is overwritten rather than appended to.
use log::info; use log::LevelFilter; use poly_logger::FileLogger; let mut logger = FileLogger::new(LevelFilter::Info); logger.timestamp_format("%F %X%.3f %Z") .msg_format("{level} [{timestamp} {file}:{line}] - {args}") .truncate(false) .filename("./test.log"); logger.init().unwrap(); info!("This is an INFO message with custom formatting");
Note
The call to new() is actually returning an instance of GenLogger
Implementations
impl FileLogger
[src]
pub fn new(level_filter: LevelFilter) -> FileLogger
[src]
Unlike the StderrLogger or StdoutLogger we return a
FileLogger struct instead of a GenLogger struct as
we need to specify file-specific options after creation.
A call to create() returns the GenLogger
pub fn init(&self) -> Result<(), SetLoggerError>
[src]
Calls create() to get the GenLogger instance which is then in turn initialized.
pub fn timestamp_format(&mut self, format: &'static str) -> &mut Self
[src]
Sets timestamp format for the underlying GenLogger instance
pub fn msg_format(&mut self, format: &'static str) -> &mut Self
[src]
Sets message format for the underlying GenLogger instance
pub fn truncate(&mut self, truncate: bool) -> &mut Self
[src]
Truncates log file before writing. Default is to append
pub fn filename(&mut self, filename: &'static str) -> &mut Self
[src]
Sets log file name
pub fn create(&self) -> GenLogger<File>
[src]
We need to call this to get a Log interface object such as when passing to PolyLogger. If this is a standalone logger, create() will be called when do the init().
Auto Trait Implementations
impl RefUnwindSafe for FileLogger
impl Send for FileLogger
impl Sync for FileLogger
impl Unpin for FileLogger
impl UnwindSafe for FileLogger
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,