Robot Framework logging full traceback of errors and exceptions

#robot framework#python

27 June 2025

I prefer having a full traceback of an error in case of a failing Robot Framework test case. But by default Robot Framework only shows the message of an exception. You get to know the failing keyword but no details about the underlying python code which threw the exception. You can retrieve this information either by changing the log level or via a custom Robot Framework Listener. In this article I will explain both approaches.

Changing log level to debug or below

Robot Framework will log the full traceback in case you set the log level to TRACE or DEBUG

  • set log levels as described here in the Robot Framework user guide

  • in case you use RobotCode you can configure the log level via a robot.toml file

    robot.toml
    # https://robotcode.io/02_get_started/configuration
    # Basic settings
    output-dir = "output"
    
    # log-level = "NONE"
    log-level = "INFO"
    # log-level DEBUG (or TRACE) would show full traceback
    # as debug level by default
    # log-level = "DEBUG"
    # log-level = "TRACE"

Robot Framework Listener which logs traceback

Alternatively you can create a custom Robot Framework Listener that will log the full traceback as error in case a keyword fails.
This way you can keep the over all log level at info or above.

I explain Robot Framework listeners with more detail in this other article about structured logging for Robot Framework.

Listener implementation

You can find the complete code in my git repository python-ideas (links to fixed commit).

Robot Framework provides a method which returns the error message and full traceback of the last occurred exception (see Robot Framework docs: robot.utils.error).
You can this method as shown in the following code block:

python-ideas/robotframework-tips/robotframework_tips/utils/robot_listeners/ExceptionTracebackListener.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from robot import running, result
from robot.api import logger as robot_logger
from robot.utils.error import get_error_details
from typing import Literal


class ExceptionTracebackListener:

    ROBOT_LIBRARY_SCOPE = "GLOBAL"
    ROBOT_LISTENER_API_VERSION = 3

    def __init__(
        self,
        exception_details_log_level: Literal["DEBUG", "INFO", "WARN", "ERROR"] = "INFO",
    ):
        match exception_details_log_level:
            case "DEBUG":
                self.logger_func = robot_logger.debug
            case "INFO":
                self.logger_func = robot_logger.info
            case "WARN":
                self.logger_func = robot_logger.warn
            case "ERROR":
                self.logger_func = robot_logger.error
            case _:
                raise ValueError("invalid value for exception_details_log_level")

    # https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#listener-version-3
    def end_keyword(self, data: running.Keyword, result: result.Keyword):
        if result.status == "FAIL":
            error_message, error_traceback = get_error_details(full_traceback=True)

            trace_details = (
                f"keyword failed with error message: {error_message}\n"
                f"{error_traceback}"
            )
            self.logger_func(msg=trace_details)

Run test case with listener

As described in the other article about the StructlogListener you have to add the ExceptionTracebackListener as robot cli argument (--listener) or via robot.toml file that is used by the RobotCode vscode extension:

robot.toml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# https://robotcode.io/02_get_started/configuration
# Basic settings
output-dir = "output"

# log-level = "NONE"
log-level = "INFO"
# log-level DEBUG (or TRACE) would show full traceback
# as debug level by default
# log-level = "DEBUG"
# log-level = "TRACE"

languages = ["en", "de"]
# console = "verbose"
# using dotted console output avoids strange line breaks
# between stdout and stderr output of the verbose version
console = "dotted"

# add your custom listeners here:
[listeners]
'robotframework_tips.utils.robot_listeners.ExceptionTracebackListener' = [
  'INFO', # exception detail log level
]
'robotframework_tips.utils.robot_listeners.StructlogListener' = [
  "true",  # colors
  "false", # full path (structlog)
]

Check traceback in logs

Check the Robot Framework log.html file.
It will contain your custom traceback log messages with the defined log levels.

Related content