Current use case: Say I’ve a standalone Python library called X.
- I call X using my created Robot library that uses Robot listeners.
- The X library I call uses Python’s logging module to do logging.
- X library shouldn’t itself be modified to use Robot’s ways of doing console logging.
What I’m trying to do is, I need to be able to do console logging for logs coming from X when I run Robot Framework.
It seems like Robot doesn’t catch logs coming from listeners (Although, it catches logs with levels more severe than ‘INFO’)… Example library:
class ExampleLibrary:
ROBOT_LIBRARY_SCOPE = "GLOBAL"
ROBOT_LIBRARY_DOC_FORMAT = "TEXT"
ROBOT_LIBRARY_VERSION = "0.1"
ROBOT_LISTENER_API_VERSION = 2
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
self.ROBOT_LIBRARY_LISTENER = self
self._log = logging.getLogger("ExampleLogger")
self._log.setLevel(logging.NOTSET)
self._log.addHandler(logging.StreamHandler())
self._log.info("Initialized ExampleLibrary")
def _start_suite(self, test_suite, result) -> None:
# We do calls to X here..
# X creates its loggers and sends logs like the following line
self._log.debug("suite started!")
def _end_suite(self, test_suite, result):
# We do calls to X here..
# X creates its loggers and sends logs like the following line
self._log.debug("suite ended!")
def try_log(self):
self._log.debug("trying debug log")
self._log.warning("trying warning log")
self._log.error("trying error log")
Example suite:
*** Settings ***
Library ./ExampleLibrary.py
*** Test Cases ***
Passed Test
TRY LOG
Trying to run the above suite.robot file using robot suite.robot
:
Initialized FirstLibrary
==============================================================================
Suite
==============================================================================
[ WARN ] trying warning log
[ ERROR ] trying error log
Passed Test | PASS |
------------------------------------------------------------------------------
Suite | PASS |
1 test, 1 passed, 0 failed
==============================================================================
So, is there a way to make Robot Framework log messages coming from listeners ?