[−][src]Struct poly_logger::GenLogger
Implements a generic logger for use with different types of writers
Simple Example
Instantiates a STDERR logger with default message and timestamp format
use log::{info,LevelFilter}; use poly_logger::GenLogger; let mut logger = GenLogger::new(LevelFilter::Info, std::io::stderr()); logger.init().unwrap(); info!("This is an INFO message");
Customized Example
Instantiates a STDOUT logger with custom timestamp format and message format
use log::{info,LevelFilter}; use poly_logger::GenLogger; let mut logger = GenLogger::new(LevelFilter::Info, std::io::stdout()); logger.timestamp_format("%X%.6f") .msg_format("[{timestamp} {file}:{line}] - {level} - {args}"); logger.init().unwrap(); info!("This is a custom INFO message"); // Output is something like: // [20:52:57.909459 examples/stdout.rs:14] - INFO - This is a custom INFO message
Fields
log_formatter: LogFormatter
Implementations
impl<T> GenLogger<T> where
T: Write + Sync + Send + 'static,
[src]
T: Write + Sync + Send + 'static,
pub fn new(level_filter: LevelFilter, writer: T) -> Self
[src]
Instantiate a new GenLogger with the given log level filter and a Writer instance
pub fn init(self) -> Result<(), SetLoggerError>
[src]
Initializes the log interface using this GenLogger as a boxed logger. This moves self so is the last method to call on this object.
pub fn timestamp_format(&mut self, format: &'static str) -> &mut Self
[src]
Sets the timestamp format to use in our log messages.
The format string may be any valid format from the chrono::format::strftime module.
If format is set to "" the timestamp will not be calculated/formatted, which is more efficient if if timestamp is not part of the message format.
The default timestamp format of '%+' (ISO 8601 / RFC 3339 date & time format)
will be used if you do not call timestamp_format(
pub fn msg_format(&mut self, format: &'static str) -> &mut Self
[src]
Sets the format for message written by our logger
The format can use any combination of the following placeholders
- {timestamp} - Date/time stamp of this message
- {level} - The log::Level for this message
- {file} - The Rust source file where the log message was generated
- {line} - The line in the Rust source file where the log message was generated
- {args} - The log message itself
Note that the names of the placeholders come from the corresponding definitions in log::Record.
This method relies on the strfmt crate which gives us flexibility at the expense of being somewhat expensive. It's our best option as of late 2020 though.
The default format is: [{timestamp}] {level} [{file}:{line}] {args}
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for GenLogger<T>
impl<T> Send for GenLogger<T>
impl<T> Sync for GenLogger<T>
impl<T> Unpin for GenLogger<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for GenLogger<T>
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>,