pub struct LogFormatter { /* private fields */ }Expand description
Formats raw log structs into log messages by applying both the log message’s configuration and the formatter’s own settings.
§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 enable_log_header_color(&mut self)
pub fn enable_log_header_color(&mut self)
Enables the log headers to have colors.
Sourcepub fn disable_log_header_color(&mut self)
pub fn disable_log_header_color(&mut self)
Disables colored log headers.
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.
Returns an error when the %m placeholder is missing.
There are several placeholders in a log format string:
%m: The log message (this placeholder is mandatory, you will get an error if you don’t include it in your log format).%h: The header indicating the log type (e.g., debug, error, etc.)%d: The timestamp.
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!")));Trait Implementations§
Source§impl Clone for LogFormatter
impl Clone for LogFormatter
Source§fn clone(&self) -> LogFormatter
fn clone(&self) -> LogFormatter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more