logger - Logging Facility
DTS logger module.
The module provides several additional features:
The storage of DTS execution stages,
Logging to console, a human-readable log file and a machine-readable log file,
Optional log files for specific stages.
- class DtsStage
Bases:
StrEnum
The DTS execution stage.
- pre_run = 'pre_run'
- test_run_setup = 'test_run_setup'
- test_suite_setup = 'test_suite_setup'
- test_suite = 'test_suite'
- test_suite_teardown = 'test_suite_teardown'
- test_run_teardown = 'test_run_teardown'
- post_run = 'post_run'
- class DTSLogger
Bases:
Logger
The DTS logger class.
The class extends the
Logger
class to add the DTS execution stage information to log records. The stage is common to all loggers, so it’s stored in a class variable.Any time we switch to a new stage, we have the ability to log to an additional log file along with a supplementary log file with machine-readable format. These two log files are used until a new stage switch occurs. This is useful mainly for logging per test suite.
- __init__(*args, **kwargs)
Extend the constructor with extra file handlers.
- add_dts_root_logger_handlers(verbose: bool, output_dir: str) None
Add logger handlers to the DTS root logger.
This method should be called only on the DTS root logger. The log records from child loggers will propagate to these handlers.
Three handlers are added:
A console handler,
A file handler,
A supplementary file handler with machine-readable logs containing more debug information.
All log messages will be logged to files. The log level of the console handler is configurable with verbose.
- Parameters:
verbose (bool) – If
True
, log all messages to the console. IfFalse
, log to console with thelogging.INFO
level.output_dir (str) – The directory where the log files will be located. The names of the log files correspond to the name of the logger instance.
- set_stage(stage: DtsStage, log_file_path: pathlib.Path | None = None) None
Set the DTS execution stage and optionally log to files.
Set the DTS execution stage of the DTSLog class and optionally add file handlers to the instance if the log file name is provided.
The file handlers log all messages. One is a regular human-readable log file and the other one is a machine-readable log file with extra debug information.
- Parameters:
stage (DtsStage) – The DTS stage to set.
log_file_path (pathlib.Path | None) – An optional path of the log file to use. This should be a full path (either relative or absolute) without suffix (which will be appended).
- get_dts_logger(name: str | None = None) DTSLogger
Return a DTS logger instance identified by name.
- Parameters:
name (str | None) – If
None
, return the DTS root logger. If specified, return a child of the DTS root logger.- Returns:
The DTS root logger or a child logger identified by name.
- Return type: