Project

Profile

Help

Issue #850

closed

Log handler fails if trace contains non-ascii

Added by jortel@redhat.com about 9 years ago. Updated about 5 years ago.

Status:
CLOSED - WONTFIX
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
Due date:
Estimated time:
Severity:
3. High
Version:
2.6.0
Platform Release:
OS:
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Pulp 2
Sprint:
Quarter:

Description

The log handler appends the stack trace to the log record here:

    def emit(self, record):
        """
        This gets called whenever a log message needs to get sent to the syslog. This method will
        inspect the record, and if it contains newlines, it will break the record into multiple
        records. For each of those records, it will also verify that they are no longer than
        MAX_MSG_LENGTH octets. If they are, it will break them up at that boundary as well.

        :param record: The record to be logged via syslog
        :type  record: logging.LogRecord
        """
        if record.exc_info:
            trace = self.formatter.formatException(record.exc_info)
            if not isinstance(record.msg, basestring):
                record.msg = unicode(record.msg)
            record.msg += u'\n'
            record.msg += trace.replace('%', '%%')  <------------------ HERE
            record.exc_info = None
        formatter_buffer = self._calculate_formatter_buffer(record)

The formatException method returns a str and appears to convert unicode to UTF-8. So, if an
exception contains either UTF-8 or unicode, this method returns a string containing non-ASCII.

This concatenation fails.

record.msg += trace.replace('%', '%%')

This results in the following exception:


  File "/usr/lib64/python2.7/logging/__init__.py", line 1193, in exception
    self.error(msg, *args, **kwargs)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1186, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1279, in _log
    self.handle(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1289, in handle
    self.callHandlers(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1329, in callHandlers
    hdlr.handle(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 757, in handle
    self.emit(record)
  File "/home/jortel/git/pulp/server/pulp/server/logs.py", line 126, in emit
    record.msg += trace.replace('%', '%%')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 434: ordinal not in range(128)

Also available in: Atom PDF