Struct the_logger::TheLogger
source · pub struct TheLogger { /* private fields */ }
Expand description
Main struct to instantiate when using TheLogger. Its inner RwLock allows only one usage of the file writer and configuration member at a time.
Implementations§
source§impl TheLogger
impl TheLogger
sourcepub fn instance() -> &'static Self
pub fn instance() -> &'static Self
Description
Returns the instance of the logger. This is the main way to access the logger, and it’ll be configured by default.
TheLogger has built-in support for the format! macro, so the user can use it to format the log message without having to allocate an extra variable, as shown in the example below.
Its setup can be changed later using the methods provided by this crate.
Default settings:
- All date elements enabled
- All time elements enabled
- Log level enabled and set to VERBOSE
- Time format set to Local time
- File name and line number shown, but column number is hidden.
- File name, location, column information section is limited to a maximum default of 60 chars, configurable.
- Log content is limited to a maximum default of 300 chars, also configurable.
Log Example
2023-12-16 17:08:07.451851800 [VERBOSE] This is a log example for the the_logger crate
Usage example
use the_logger::{log_warning, TheLogger};
async fn init_logger(thread_id: u8) {
let logger: &TheLogger = TheLogger::instance();
log_warning!(logger, "This is a warning emitted by thread {}", thread_id);
}
sourcepub async fn log_in_file(&self, __arg1: (&str, u32, u32), incoming_msg: &str)
pub async fn log_in_file(&self, __arg1: (&str, u32, u32), incoming_msg: &str)
Description
Executes the logging to the file according to the current configuration
sourcepub async fn config(&self, logger_config: TheLoggerConfig) -> &Self
pub async fn config(&self, logger_config: TheLoggerConfig) -> &Self
Description
Allows the user to configure the logger using a single config call. The configuration must previously be created by instantiating the TheLoggerConfig struct adn setting each desired field with its builder methods.
Every change to the configuration is made through this method.
Initial configuration example
use the_logger::{TheLogger, TheLoggerConfig};
async fn init_logger() {
let logger_config = TheLoggerConfig::default()
.hide_file_line()
.hide_microsecs()
.hide_level();
let logger: &TheLogger = TheLogger::instance().config(logger_config).await;
}
As a result, the user has configured the logger to hide the file line number, the microsecs and the log level,
and leave the rest of the parameters with their default values.
Modifying configuration example
If the user needs to modify the logger configuration for any particular reason, for example for a specific
routine that doesn’t need to show all the data or needs to show different data, this can be achieved in a similar
way to the initial configuration:
use the_logger::{TheLogger, TheLoggerConfig};
async fn config_logger() {
let logger_config = TheLoggerConfig::default()
.show_file_line()
.show_microsecs()
.show_level();
let logger: &TheLogger = TheLogger::instance().config(logger_config).await;
}
As opposed to the previous example, we’re now reverting the changes made to the logger configuration, so that
the file line number, microseconds stamp and log level are shown.
sourcepub async fn verbose(&self) -> &Self
pub async fn verbose(&self) -> &Self
Description
Configures the log level as verbose adding the [[VERBOSE]] tag
sourcepub async fn info(&self) -> &Self
pub async fn info(&self) -> &Self
Description
Configures the log level as informational adding the [[INFO]] tag
sourcepub async fn error(&self) -> &Self
pub async fn error(&self) -> &Self
Description
Configures the log level as error adding the [[ERROR]] tag
sourcepub async fn warning(&self) -> &Self
pub async fn warning(&self) -> &Self
Description
Configures the log level as warning adding the [[WARNING]] tag
sourcepub async fn debug(&self) -> &Self
pub async fn debug(&self) -> &Self
Description
Configures the log level as debug adding the [[DEBUG]] tag
sourcepub async fn trace(&self) -> &Self
pub async fn trace(&self) -> &Self
Description
Configures the log level as trace adding the [[TRACE]] tag
sourcepub async fn critical(&self) -> &Self
pub async fn critical(&self) -> &Self
Description
Configures the log level as critical adding the [[CRITICAL]] tag
sourcepub async fn hide_years(&self) -> &Self
pub async fn hide_years(&self) -> &Self
Description
Configures the log date to hide the years. Default is to show them
sourcepub async fn hide_months(&self) -> &Self
pub async fn hide_months(&self) -> &Self
Description
Configures the log date to hide the months. Default is to show them
sourcepub async fn hide_days(&self) -> &Self
pub async fn hide_days(&self) -> &Self
Description
Configures the log date to hide the days. Default is to show them
sourcepub async fn hide_hours(&self) -> &Self
pub async fn hide_hours(&self) -> &Self
Description
Configures the log time to hide the hours. Default is to show them
sourcepub async fn hide_minutes(&self) -> &Self
pub async fn hide_minutes(&self) -> &Self
Description
Configures the log time to hide the minutes. Default is to show them
sourcepub async fn hide_seconds(&self) -> &Self
pub async fn hide_seconds(&self) -> &Self
Description
Configures the log time to hide the seconds. Default is to show them
sourcepub async fn hide_millisecs(&self) -> &Self
pub async fn hide_millisecs(&self) -> &Self
Description
Configures the log time to hide the milliseconds. Default is to show them
Warning
Hiding the milliseconds and showing the microseconds would cause an unexpected time tracking in the logs,
therefore, in this specific case, both milliseconds and microseconds will be hidden
sourcepub async fn hide_microsecs(&self) -> &Self
pub async fn hide_microsecs(&self) -> &Self
Description
Configures the log time to hide the microseconds. Default is to show them
Warning
Hiding the milliseconds and showing the microseconds would cause an unexpected time tracking in the logs,
therefore, in this specific case, both milliseconds and microseconds will be hidden
sourcepub async fn utc_time(&self) -> &Self
pub async fn utc_time(&self) -> &Self
Description
Configures the log timezone to UTC format. Default is Local time
sourcepub async fn hide_level(&self) -> &Self
pub async fn hide_level(&self) -> &Self
Description
Configures the log level to be hidden. Default is to show it
sourcepub async fn hide_file_name(&self) -> &Self
pub async fn hide_file_name(&self) -> &Self
Description
Configures the log file name, line and column to be hidden. Default is to show them
sourcepub async fn hide_file_line(&self) -> &Self
pub async fn hide_file_line(&self) -> &Self
Description
Configures the log file line and column to be hidden. Default is to show them
sourcepub async fn show_file_column(&self) -> &Self
pub async fn show_file_column(&self) -> &Self
Description
Configures the log file column to be shown. Default is to hide it
sourcepub async fn show_years(&self) -> &Self
pub async fn show_years(&self) -> &Self
Description
Configures the log date to show the years. Default is to show them
sourcepub async fn show_months(&self) -> &Self
pub async fn show_months(&self) -> &Self
Description
Configures the log date to show the months. Default is to show them
sourcepub async fn show_days(&self) -> &Self
pub async fn show_days(&self) -> &Self
Description
Configures the log date to show the days. Default is to show them
sourcepub async fn show_hours(&self) -> &Self
pub async fn show_hours(&self) -> &Self
Description
Configures the log time to show the hours. Default is to show them
sourcepub async fn show_minutes(&self) -> &Self
pub async fn show_minutes(&self) -> &Self
Description
Configures the log time to show the minutes. Default is to show them
sourcepub async fn show_seconds(&self) -> &Self
pub async fn show_seconds(&self) -> &Self
Description
Configures the log time to show the seconds. Default is to show them
sourcepub async fn show_millisecs(&self) -> &Self
pub async fn show_millisecs(&self) -> &Self
Description
Configures the log time to show the milliseconds. Default is to show them
Warning
Hiding the milliseconds and showing the microseconds would cause an unexpected time tracking in the logs,
therefore, in this specific case, both milliseconds and microseconds will be hidden
sourcepub async fn show_microsecs(&self) -> &Self
pub async fn show_microsecs(&self) -> &Self
Description
Configures the log time to show the microseconds. Default is to show them
Warning
Hiding the milliseconds and showing the microseconds would cause an unexpected time tracking in the logs,
therefore, in this specific case, both milliseconds and microseconds will be hidden
sourcepub async fn local_time(&self) -> &Self
pub async fn local_time(&self) -> &Self
Description
Configures the log timezone to Local format. Default is Local time
sourcepub async fn show_level(&self) -> &Self
pub async fn show_level(&self) -> &Self
Description
Configures the log level to be shown. Default is to show it
sourcepub async fn show_file_name(&self) -> &Self
pub async fn show_file_name(&self) -> &Self
Description
Configures the log file name, line and column to be shown. Default is to show them
sourcepub async fn show_file_line(&self) -> &Self
pub async fn show_file_line(&self) -> &Self
Description
Configures the log file line and column to be shown. Default is to show them
sourcepub async fn hide_file_column(&self) -> &Self
pub async fn hide_file_column(&self) -> &Self
Description
Configures the log file column to be shown. Default is to hide it
sourcepub async fn location_content_length(&self, length: usize) -> &Self
pub async fn location_content_length(&self, length: usize) -> &Self
Description
Configures the log file name, line and column location content’s length. Default is 100 characters
sourcepub async fn log_content_length(&self, length: usize) -> &Self
pub async fn log_content_length(&self, length: usize) -> &Self
Description
Configures the log message content’s length. Default is 300 characters