Skip to content

Include exception traceback to messages logged using logging.exception #3828

Closed

Description

@CarstenLeue

consider this python code that occurs e.g. in a library:

def do_something():
  raise IOError('my error')

logger = logging.getLogger(__name__)

def do_something_else():
  try:
      do_something()
  except IOError:
      logger.exception('Catching error')


...
    @keyword()
    def my_keyword(self):
        do_something_else()

If I am executing the My Keyword in my testcase then the exception printed by logger.exception will only print out the immediate exception message Catching error but nothing about the traceback of this exception.

This is due to the fact that https://github.com/robotframework/robotframework/blob/master/src/robot/output/pyloggingconf.py#L62 is not considering the exc_info on the logging record.

The behaviour is different compared to the standard python logger that would log the exc_info and provides information about the traceback.

The use of logger.exception as in this example is the suggested way - afaik - in python to log exceptions. You would not add the original exception message to the message argument to logger.exception because - normally - this would lead to a duplication of error messages.

The robot logger however swallows this exception hierachy.

The expected behaviour is to contain the exc_info structure in the log output.

Activity

  1. pekkaklarck commented on Mar 3, 2021

    @pekkaklarck
    Member

    I can reproduce this. Adding the traceback into the message would be pretty easy. That changes the error to something like this:

    [ ERROR ] Catching error                                                      
    Traceback (most recent call last):
      File "/home/peke/Devel/robotframework/tmp/3828.py", line 10, in do_something_else
        do_something()
      File "/home/peke/Devel/robotframework/tmp/3828.py", line 4, in do_something
        raise IOError('my error')
    OSError: my error
    
  2. added this to the v4.0 milestone on Mar 3, 2021
  3. changed the title [-]The Robot Logger for Python does not log the Exception trace[/-] [+]Include exception traceback to messages logged using `logging.exception`[/+] on Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions