Module log

Source
Expand description

The log module defines an interface to Ixa’s internal logging facilities. Logging messages about internal behavior of Ixa. This is not to be confused with reporting, which is model-level concept for Ixa users to record data about running models.

Model authors can nonetheless use Ixa’s logging facilities to output messages. This module (re)exports the five logging macros: error!, warn!, info!, debug! and trace! where error! represents the highest-priority log messages and trace! the lowest. To emit a log message, simply use one of these macros in your code:

use ixa::{info};

pub fn do_a_thing() {
    info!("A thing is being done.");
}

Logging is disabled by default. Logging messages can be enabled by passing the command line option --log-level <level>. Log messages can also be controlled programmatically. Logging can be enabled/disabled from code using the functions:

  • enable_logging(): turns on all log messages
  • disable_logging(): turns off all log messages
  • set_log_level(level: LevelFilter): enables only log messages with priority at least level

In addition, per-module filtering of messages can be configured using set_module_filter() / set_module_filters() and remove_module_filter():

use ixa::log::{set_module_filter, remove_module_filter, set_module_filters, LevelFilter,
enable_logging, set_log_level};

pub fn setup_logging() {
    // Enable `info` log messages globally.
    set_log_level(LevelFilter::Info);
    // Disable Ixa's internal logging messages.
    set_module_filter("ixa", LevelFilter::Off);
    // Enable all log messages for the `transmission_manager` module.
    set_module_filter("transmission_manager", LevelFilter::Trace);
}

Macros§

debug
Logs a message at the debug level.
error
Logs a message at the error level.
info
Logs a message at the info level.
trace
Logs a message at the trace level.
warn
Logs a message at the warn level.

Enums§

LevelFilter
An enum representing the available verbosity level filters of the logger.

Functions§

disable_logging
Disables logging completely. Equivalent to set_log_level(LevelFilter::Off).
enable_logging
Enables the logger with no global level filter / full logging. Equivalent to set_log_level(LevelFilter::Trace).
remove_module_filter
Removes a module-specific level filter for the given module path. The global level filter will apply to the module.
set_log_level
Sets the global log level. A global filter level of LevelFilter::Off disables logging.
set_module_filter
Sets a level filter for the given module path.
set_module_filters
Sets the level filters for a set of modules according to the provided map. Use this instead of set_module_filter() to set filters in bulk.