[][src]Struct poly_logger::FileLogger

pub struct FileLogger { /* fields omitted */ }

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. The StderrLogger struct is just a way to instantiate a GenLogger with Stderr as the target for output. See GenLogger for the full list of methods that can be called on the logger instance.

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 instance we need, though this is typically done by calling init().

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.