nicetoolbox.utils.logging_utils

Helper functions for logging.

Functions

assert_and_log

Asserts a condition and logs an error message if the condition is not met.

log_configs

Logs the configurations to a file.

setup_custom_logging

Start logger.

setup_logging

Start logger.

nicetoolbox.utils.logging_utils.assert_and_log(condition, message)[source]

Asserts a condition and logs an error message if the condition is not met.

Parameters:
  • condition (bool) – The condition to be checked.

  • message (str) – The error message to be logged if the condition is not met.

Returns:

None

Raises:
  • AssertionError – If the condition is not met.

  • SystemExit – If the condition is not met, the function will terminate the program with a status code of 1.

nicetoolbox.utils.logging_utils.log_configs(configs: dict, out_folder: str, file_name: str = 'log_config') None[source]

Logs the configurations to a file.

The function takes in a dictionary of configurations, an output folder path, and an optional file name. It fills in placeholders in the code_config dictionary with actual values using the config_fill_auto function. Then, it constructs the log file path by joining the output folder path and the file name with a .toml extension. After that, it updates the configs dictionary with the filled code_config and saves the configurations to the log file using the save_config function.

Parameters:
  • configs (dict) – A dictionary containing the configurations to be logged.

  • out_folder (str) – The path to the output folder where the log file will be saved.

  • file_name (str, optional) – The name of the log file. Defaults to ‘log_config’.

Returns:

None

nicetoolbox.utils.logging_utils.setup_custom_logging(log_path: str, name: str, level=10) None[source]

Start logger.

Parameters:
  • log_path (str) – The path to the log file.

  • level (int, optional) –

    Determines from which level the logger will record the messages. For instance, when the level is set as logging.INFO, the messages with a severity below INFO (i.e. DEBUG) will be ignored. The possible levels are:

    • logging.DEBUG: Detailed information, typically of interest only when

    diagnosing problems. - logging.INFO: Confirmation that things are working as expected. - logging.WARNING: An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’).

    The software is still working as expected.

    • logging.ERROR: Due to a more serious problem, the software has not

    been able to perform some function. - logging.CRITICAL: A serious error, indicating that the program itself may be unable to continue running.

Returns:

None

nicetoolbox.utils.logging_utils.setup_logging(log_path: str, level=10) None[source]

Start logger.

Parameters:
  • log_path (str) – The path to the log file.

  • level (int, optional) –

    Determines from which level the logger will record the messages. For instance, when the level is set as logging.INFO, the messages with a severity below INFO (i.e. DEBUG) will be ignored. The possible levels are:

    • logging.DEBUG: Detailed information, typically of interest only when

    diagnosing problems. - logging.INFO: Confirmation that things are working as expected. - logging.WARNING: An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’).

    The software is still working as expected.

    • logging.ERROR: Due to a more serious problem, the software has not

    been able to perform some function. - logging.CRITICAL: A serious error, indicating that the program itself may be unable to continue running.

Returns:

None