pub struct LogFormatter { /* private fields */ }Expand description
The LogFormatter is used for turning raw log structs into log messages
based on its configuration.
§Examples
Using a LogFormatter to print a log:
// Create a `LogFormatter` with default configuration
let mut formatter = LogFormatter::default();
// Set a log format
formatter.set_log_format("[ %h %m ]");
// Obtain a formatted log from a `LogStruct`
let log = formatter.format_log(&LogStruct::debug("Hello from LogStruct!"));
// Print the formatted log message
print!("{}", &log);Implementations§
Source§impl LogFormatter
impl LogFormatter
Sourcepub fn format_log(&mut self, log: &LogStruct) -> String
pub fn format_log(&mut self, log: &LogStruct) -> String
Returns a log entry from a LogStruct based on current LogFormatter
configuration.
§Examples
let mut formatter = LogFormatter::default();
let log_string = formatter.format_log(&LogStruct::error("Error!"));Sourcepub fn toggle_log_header_color<I: Into<bool>>(&mut self, enabled: I)
pub fn toggle_log_header_color<I: Into<bool>>(&mut self, enabled: I)
Toggles colored log headers.
true: Log headers will have colorsfalse: No colors :(
Sourcepub fn set_debug_color<I: Into<Color>>(&mut self, color: I)
pub fn set_debug_color<I: Into<Color>>(&mut self, color: I)
Sets debug log header color.
Sourcepub fn set_info_color<I: Into<Color>>(&mut self, color: I)
pub fn set_info_color<I: Into<Color>>(&mut self, color: I)
Sets info log header color.
Sourcepub fn set_warning_color<I: Into<Color>>(&mut self, color: I)
pub fn set_warning_color<I: Into<Color>>(&mut self, color: I)
Sets warning header color.
Sourcepub fn set_error_color<I: Into<Color>>(&mut self, color: I)
pub fn set_error_color<I: Into<Color>>(&mut self, color: I)
Sets error header color.
Sourcepub fn set_fatal_color<I: Into<Color>>(&mut self, color: I)
pub fn set_fatal_color<I: Into<Color>>(&mut self, color: I)
Sets fatal error header color.
Sourcepub fn set_debug_header(&mut self, header: &str)
pub fn set_debug_header(&mut self, header: &str)
Sets debug log header format.
Sourcepub fn set_info_header(&mut self, header: &str)
pub fn set_info_header(&mut self, header: &str)
Sets info log header format.
Sourcepub fn set_warning_header(&mut self, header: &str)
pub fn set_warning_header(&mut self, header: &str)
Sets warning header format.
Sourcepub fn set_error_header(&mut self, header: &str)
pub fn set_error_header(&mut self, header: &str)
Sets error header format.
Sourcepub fn set_fatal_header(&mut self, header: &str)
pub fn set_fatal_header(&mut self, header: &str)
Sets fatal error header format.
Sourcepub fn set_datetime_format(&mut self, format: &str)
pub fn set_datetime_format(&mut self, format: &str)
Sets datetime format.
Sourcepub fn set_log_format(&mut self, format: &str) -> Result<(), Error>
pub fn set_log_format(&mut self, format: &str) -> Result<(), Error>
Sets the log format.
There are several placeholders in a log format string:
%d: The timestamp.%h: The header indicating the log type (e.g., debug, error, etc.)%m: The log message (this placeholder is mandatory, you will get an error if you don’t include it in your log format).
You can have multiple placeholders of the same type in a format string.
§Examples
let mut formatter = LogFormatter::default();
// Do a nice XML-like format
formatter.set_log_format("<l> <h>%h</h> <m>%m</m> </l>");
print!("{}", formatter.format_log(&LogStruct::debug("Hello, World!")));Returns an error when the %m placeholder is missing.
Trait Implementations§
Source§impl Clone for LogFormatter
impl Clone for LogFormatter
Source§fn clone(&self) -> LogFormatter
fn clone(&self) -> LogFormatter
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LogFormatter
impl Debug for LogFormatter
Source§impl Default for LogFormatter
impl Default for LogFormatter
Source§fn default() -> LogFormatter
fn default() -> LogFormatter
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for LogFormatter
impl<'de> Deserialize<'de> for LogFormatter
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Hash for LogFormatter
impl Hash for LogFormatter
Source§impl Ord for LogFormatter
impl Ord for LogFormatter
Source§fn cmp(&self, other: &LogFormatter) -> Ordering
fn cmp(&self, other: &LogFormatter) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for LogFormatter
impl PartialEq for LogFormatter
Source§impl PartialOrd for LogFormatter
impl PartialOrd for LogFormatter
Source§impl Serialize for LogFormatter
impl Serialize for LogFormatter
impl Eq for LogFormatter
impl StructuralPartialEq for LogFormatter
Auto Trait Implementations§
impl Freeze for LogFormatter
impl RefUnwindSafe for LogFormatter
impl Send for LogFormatter
impl Sync for LogFormatter
impl Unpin for LogFormatter
impl UnwindSafe for LogFormatter
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