Issue #850
closedLog handler fails if trace contains non-ascii
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)
Updated by jortel@redhat.com almost 9 years ago
- Subject changed from Log handler fails if trace contains utf-8 to Log handler fails if trace contains non-ascii
Updated by mhrivnak almost 9 years ago
- Triaged changed from No to Yes
This has not yet been seen in the wild (to our knowledge), but rather was found by a unit test (yay!).
Updated by bmbouter almost 5 years ago
- Status changed from NEW to CLOSED - WONTFIX
Updated by bmbouter almost 5 years ago
Pulp 2 is approaching maintenance mode, and this Pulp 2 ticket is not being actively worked on. As such, it is being closed as WONTFIX. Pulp 2 is still accepting contributions though, so if you want to contribute a fix for this ticket, please reopen or comment on it. If you don't have permissions to reopen this ticket, or you want to discuss an issue, please reach out via the developer mailing list.