climate_ref_core.logging
#
Logging utilities
The REF uses loguru, a simple logging framework. The log level and format are configured via the REF configuration file.
DEFAULT_LOG_FORMAT = '<green>{time:YYYY-MM-DD HH:mm:ss.SSS Z}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan> - <level>{message}</level>'
module-attribute
#
Default log format used by the REF
EXECUTION_LOG_FILENAME = 'out.log'
module-attribute
#
Filename for the execution log.
This file is written via climate_ref_core.logging.redirect_logs.
VERBOSE_LOG_FORMAT = '<green>{time:YYYY-MM-DD HH:mm:ss.SSS Z} e{elapsed}s</green> | <level>{level: <8}</level> | {process.name}:{process.id} | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>'
module-attribute
#
The verbose log format is used for debugging and development.
This is the format that is used when writing the log messages to file for later debugging. It contains information about the process and function that the log message was generated in.
add_log_handler(**kwargs)
#
Add a log sink to the logger to capture logs.
This is useful for testing purposes, to ensure that logs are captured correctly.
Source code in packages/climate-ref-core/src/climate_ref_core/logging.py
capture_logging()
#
Capture logging from the standard library and redirect it to Loguru
Note that this replaces the root logger, so any other handlers attached to it will be removed.
Source code in packages/climate-ref-core/src/climate_ref_core/logging.py
initialise_logging(level, format, log_directory)
#
Initialise the logging for the REF
This sets up the default log handler and configures the REF logger.
Source code in packages/climate-ref-core/src/climate_ref_core/logging.py
redirect_logs(definition, log_level)
#
Temporarily redirect log output to a file.
This also writes some common log messages
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
ExecutionDefinition
|
Diagnostic definition to capture logging for |
required |
log_level
|
str
|
Log level as a string e.g. INFO, WARNING, DEBUG. This log level will dictate what logs will be sent to disk The logger will also be reset to this level after leaving the context manager. |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/logging.py
remove_log_handler()
#
Remove the default log handler from the logger.
This is useful for cleaning up after tests or when changing logging configurations.
The previously used logger kwargs are kept in logger.default_handler_kwargs if the
logger should be readded later