Crate tacky_borders_logger

Source
Expand description

§Tacky Borders Logger

This module provides macros for logging messages at different levels (debug, info, warn, error). Each macro dynamically includes the function name where it is invoked. These macros are useful for logging contextual information along with formatted messages, and they automatically capture the function name at the point where the macro is called.

§Usage

You can use these macros to log messages with the current function name included. The function name is extracted dynamically using the function_name!() macro, which returns the name of the function where it is invoked.

The macros can be used to log messages at different severity levels:

  • trace! - Logs detailed, low-level information for tracing program execution. Typically used for understanding the flow of execution, especially for debugging intricate issues. This log level provides the most granular level of detail, useful for tracking function calls, variable states, or intricate interactions between different parts of the program.
  • debug! - Logs detailed information, typically for development or debugging purposes.
  • info! - Logs general information messages.
  • warn! - Logs warnings about potential issues that aren’t necessarily errors.
  • error! - Logs error messages, typically when something goes wrong in the program.

§Example

fn example_function() {
    trace!("This is a trace message.");
    debug!("This is a debug message.");
    info!("This is an info message.");
    warn!("This is a warning message.");
    error!("This is an error message.");
}

§Function Name Extraction

The function_name!() macro uses the Rust type system to extract the name of the function dynamically. It utilizes std::any::type_name::<T>() to obtain the type name of the current function, and then processes it to extract just the function’s name. This function name is included in the log messages to provide more context about where the log entry was made.

The macros work by formatting a message and appending the function name at the end, which helps in tracing logs and identifying which function generated a particular log message.

Macros§

debug
Macro to log debug-level messages with the current function name.
error
Macro to log error-level messages with the current function name.
function_name
Macro to extract the name of the current function as a string.
info
Macro to log info-level messages with the current function name.
trace
Macro to log trace-level messages with the current function name.
warn
Macro to log warning-level messages with the current function name.