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

source

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);
}
source

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

source

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.

source

pub async fn verbose(&self) -> &Self

Description

Configures the log level as verbose adding the [[VERBOSE]] tag

source

pub async fn info(&self) -> &Self

Description

Configures the log level as informational adding the [[INFO]] tag

source

pub async fn error(&self) -> &Self

Description

Configures the log level as error adding the [[ERROR]] tag

source

pub async fn warning(&self) -> &Self

Description

Configures the log level as warning adding the [[WARNING]] tag

source

pub async fn debug(&self) -> &Self

Description

Configures the log level as debug adding the [[DEBUG]] tag

source

pub async fn trace(&self) -> &Self

Description

Configures the log level as trace adding the [[TRACE]] tag

source

pub async fn critical(&self) -> &Self

Description

Configures the log level as critical adding the [[CRITICAL]] tag

source

pub async fn hide_years(&self) -> &Self

Description

Configures the log date to hide the years. Default is to show them

source

pub async fn hide_months(&self) -> &Self

Description

Configures the log date to hide the months. Default is to show them

source

pub async fn hide_days(&self) -> &Self

Description

Configures the log date to hide the days. Default is to show them

source

pub async fn hide_hours(&self) -> &Self

Description

Configures the log time to hide the hours. Default is to show them

source

pub async fn hide_minutes(&self) -> &Self

Description

Configures the log time to hide the minutes. Default is to show them

source

pub async fn hide_seconds(&self) -> &Self

Description

Configures the log time to hide the seconds. Default is to show them

source

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

source

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

source

pub async fn utc_time(&self) -> &Self

Description

Configures the log timezone to UTC format. Default is Local time

source

pub async fn hide_level(&self) -> &Self

Description

Configures the log level to be hidden. Default is to show it

source

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

source

pub async fn hide_file_line(&self) -> &Self

Description

Configures the log file line and column to be hidden. Default is to show them

source

pub async fn show_file_column(&self) -> &Self

Description

Configures the log file column to be shown. Default is to hide it

source

pub async fn show_years(&self) -> &Self

Description

Configures the log date to show the years. Default is to show them

source

pub async fn show_months(&self) -> &Self

Description

Configures the log date to show the months. Default is to show them

source

pub async fn show_days(&self) -> &Self

Description

Configures the log date to show the days. Default is to show them

source

pub async fn show_hours(&self) -> &Self

Description

Configures the log time to show the hours. Default is to show them

source

pub async fn show_minutes(&self) -> &Self

Description

Configures the log time to show the minutes. Default is to show them

source

pub async fn show_seconds(&self) -> &Self

Description

Configures the log time to show the seconds. Default is to show them

source

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

source

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

source

pub async fn local_time(&self) -> &Self

Description

Configures the log timezone to Local format. Default is Local time

source

pub async fn show_level(&self) -> &Self

Description

Configures the log level to be shown. Default is to show it

source

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

source

pub async fn show_file_line(&self) -> &Self

Description

Configures the log file line and column to be shown. Default is to show them

source

pub async fn hide_file_column(&self) -> &Self

Description

Configures the log file column to be shown. Default is to hide it

source

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

source

pub async fn log_content_length(&self, length: usize) -> &Self

Description

Configures the log message content’s length. Default is 300 characters

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.