nicetoolbox.utils.logging_utils¶
Helper functions for logging.
Functions
Return a truncated list with an ellipsis marker when it exceeds n items. |
|
Asserts a condition and logs an error message if the condition is not met. |
|
Initialize the logging before we loaded the configuration. |
|
Initialize the logging console and file output with specific logging level. |
|
- nicetoolbox.utils.logging_utils.abbrev_list(labels: list, n: int = 5) list[source]¶
Return a truncated list with an ellipsis marker when it exceeds n items.
- 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.init_console_logging() None[source]¶
Initialize the logging before we loaded the configuration. This will log it only as a console output as we don’t know log level or output path.
- nicetoolbox.utils.logging_utils.init_file_logging(log_path: Path, level: int | str = 20) None[source]¶
Initialize the logging console and file output with specific logging level.
- Parameters:
log_path (str) – The path to the log file.
level (int | str, 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.