Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

adombeck
Copy link

@adombeck adombeck commented Jun 25, 2025

There are use cases for printing a warning or error message to the log but not to the console.

This PR adds an optional also_console argument to logger.write, logger.warn, and logger.error. Its value is stored in the message object and based on it the loggers in src/robot/output/console/ print the message or not.

Closes #5460

There are use cases for printing a warning or error message to the log
but not to the console.

This commit adds an optional also_console argument to logger.write,
logger.warn, and logger.error. Its value is stored in the message object
and based on it the loggers in src/robot/output/console/ print the
message or not.
@adombeck
Copy link
Author

@pekkaklarck it required more changes than I expected. I tested it by running robot --listener Listener.py ./test.robot with this listener:

$ cat Listener.py
from robot.api import logger

class Listener:
    def end_test(self, data, result):
        logger.info("XXX 1: end_test: INFO (should not be printed to console)")
        logger.info("XXX 2: end_test: INFO, also_console=True", also_console=True)
        logger.error("XXX 3 : end_test: ERROR (should be printed to console automatically)")
        logger.error("XXX 4: end_test: ERROR, also_console=False", also_console=False)
        logger.write("XXX 5: end_test: write, also_console=True", also_console=True)

    def end_suite(self, data, result):
        logger.info("XXX 6: end_suite: INFO (should not be printed to console)")
        logger.info("XXX 7: end_suite: INFO, also_console=True", also_console=True)
        logger.error("XXX 8: end_suite: ERROR (should be printed to console automatically)")
        logger.error("XXX 9: end_suite: ERROR, also_console=False", also_console=False)
        logger.write("XXX 10: end_suite: write, also_console=True", also_console=True)

and this suite file:

$ cat test.robot
*** Test Cases ***
My Test Case
    My Keyword

*** Keywords ***
My Keyword
    Fail

It prints the expected messages to the console (2, 3, 5, 7, 8, 10) and to the log.html file (all except 6, 7 and 10, which is due to the issue that info messages logged by the end_suite method do not end up in the log.html file).

@adombeck
Copy link
Author

@pekkaklarck any estimate when this could be reviewed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support printing errors only to the log.html file and not to the console
1 participant