Logging
StreamToLogger ¶
StreamToLogger(logger, log_level=DEBUG)
Bases: TextIOBase
Fake file-like stream object that redirects writes to a logger instance.
StreamToLogger is made to extend TextIOBase to prevent error like below when running pytest with docker-compose as part of dockerised test in developing pyderivationagent package: AttributeError: 'StreamToLogger' object has no attribute 'isatty'
To reproduce the error, one may checkout to this commit and run
pytest -s --docker-compose=./docker-compose.test.yml
in the folderThis error was due to this line in pytest checking if
sys.stdout.isatty()
is True/FalseAnother fix is to provide "def isatty(self) -> bool:"" but extending TextIOBase seems to be a "safer"/"cleaner" fix, according to this comment
Source code in JPS_BASE_LIB/python_wrapper/twa/agentlogging/logging.py
get_logger ¶
get_logger(logger_name: str)
Get the dev or prod logger (avoids having to import 'logging' in calling code).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger_name
|
str
|
name of the logger to be used, available options include 'dev' and 'prod' |
required |
Returns:
Type | Description |
---|---|
Logger to use for logging statements. |
Source code in JPS_BASE_LIB/python_wrapper/twa/agentlogging/logging.py
shutdown ¶
Shutdown the logging system, should be called before application exit after all logging calls.
clear_loggers ¶
Remove handlers from all loggers. Method adopted from this comment.