Logging Configuration

The logging_config module is responsible for setting up and configuring logging across the Firefly III Synchronization Tool. It defines a custom logging formatter and a setup function to initialize logging with the desired settings.

CustomFormatter

The CustomFormatter class in the logging_config module provides a custom logging formatter. This formatter adds color coding and additional formatting to make log messages more readable and distinguishable based on their level (DEBUG, INFO, WARNING, ERROR, CRITICAL).

class logging_config.CustomFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)

Custom formatter for logging, providing a more detailed log format.

format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

setup_logging

The setup_logging function configures the global logging level and applies the custom formatter to all log messages. This function should be called at the beginning of the script to ensure that all subsequent logging follows the configured format.

logging_config.setup_logging(level=20)

Set up logging configuration.

Usage

To use the logging configuration in your application, import the setup_logging function from the logging_config module and call it at the start of your application. Then, create logger instances in each module using logging.getLogger(__name__).

Example:

from logging_config import setup_logging

setup_logging()

logger = logging.getLogger(__name__)
logger.info("Logging is configured and ready to use.")

This setup will apply the custom logging format across your application, making log messages consistent and more informative.