tlcconfig.logger_configurator#

Logging configuration for the 3LC module, supporting default and customizable configurations.

Module Contents#

Classes#

Class

Description

LoggerConfigurator

LoggerConfigurator provide an interface to configure the 3LC logger prior to importing the tlc module.

Functions#

Function

Description

default_log_file_handler

Returns the default log fileHandler

default_dictConfig

Return the default configuration for the 3LC logger.

API#

tlcconfig.logger_configurator.default_log_file_handler() dict[str, Any]#

Returns the default log fileHandler

tlcconfig.logger_configurator.default_dictConfig() dict#

Return the default configuration for the 3LC logger.

This function return the base logging config, that can be adapted by a LoggerConfigurator instance.

Returns: A dict compatible with the logging.config.dictConfig() function.

class tlcconfig.logger_configurator.LoggerConfigurator(dictConfig: dict[str, Any] | None = None)#

LoggerConfigurator provide an interface to configure the 3LC logger prior to importing the tlc module.

LoggerConfigurator provides an interface to configure a dictionary which corresponds to version 1 of the dictConfig API. An instance of such a dictionary can be set as a class variable on the LoggerConfigurator-class, and it will be used to configure the 3LC logger when the tlc module is imported.

Once a dictConfig is fully configured, the user must call initialize_logging_config in order to set the class variable that will be used to configure the 3LC logger.

It is possible to initialize the class with a custom dictConfig to, the user is then fully responsible for this dictConfig to be valid.

initialize_logging_config(incremental: bool = False, force: bool = False) None#

Initialize the Python logging system with this configuration.

Initializing configuration should be a one-time operation done on startup. Invoking this method multiples times will have no effect unless the force parameter is set to True.

Parameters:
  • incremental – If True, the configuration will be applied incrementally. See the Python logging config documentation for more details about incremental configuration.

  • force – If True, the configuration will be applied even if it has already been applied.

static instance() tlcconfig.logger_configurator.LoggerConfigurator#

Returns the singleton LoggerConfigurator object.

set_log_level(log_level: str) None#

Set the log level for the 3LC logger.

Parameters:

log_level – The log level to set. Must be one of “DEBUG”, “INFO”, “WARNING”, “ERROR”, “CRITICAL”.

enable_log_file() None#

Enable use of a logfile for the 3LC logger.

get_current_log_file_path() str#

Returns the current log file path, if any.

Returns:

The current log file path, or an empty string if no log file is configured.

static get_next_log_level(current_log_level: str) str#

Returns the next log level in the sequence.

Parameters:

current_log_level – The current log level. Must be one of “DEBUG”, “INFO”, “WARNING”, “ERROR”, “CRITICAL”.

Returns:

The next log level in the sequence “DEBUG”, “INFO”, “WARNING”, “ERROR”, “CRITICAL”.

Raises:

ValueError – If the current log level is not one of “DEBUG”, “INFO”, “WARNING”, “ERROR”, “CRITICAL”.