Change in vdsm[master]: logging: Don't crash on non-ASCII in SimpleLogAdapter

nsoffer at redhat.com nsoffer at redhat.com
Wed Nov 18 12:01:52 UTC 2015


Nir Soffer has posted comments on this change.

Change subject: logging: Don't crash on non-ASCII in SimpleLogAdapter
......................................................................


Patch Set 3:

(1 comment)

https://gerrit.ovirt.org/#/c/48542/3/tests/utilsTests.py
File tests/utilsTests.py:

Line 1082:     def test_nonascii(self):
Line 1083:         # Just test it doesn't crash with mixture of string and unicodes in
Line 1084:         # various codings.
Line 1085:         invalid = chr(254) + chr(0)
Line 1086:         u_invalid = unichr(253) + unichr(254)
These values are not handled https://gerrit.ovirt.org/#/c/48661.

 >>> import logging
 >>> inv = '\xfe\x00'

 >>> logging.error(u"invalid string: %s", inv)
 Traceback (most recent call last):
  File "/usr/lib64/python2.7/logging/__init__.py", line 859, in emit
    msg = self.format(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 732, in format
    return fmt.format(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 471, in format
    record.message = record.getMessage()
  File "/usr/lib64/python2.7/logging/__init__.py", line 335, in getMessage
    msg = msg % self.args
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe in position 0: ordinal not in range(128)
 Logged from file <stdin>, line 1

It would be nicer if such values would print garbage instead:

 >>> logging.error("invalid string: %s", inv)
 ERROR:root:invalid string: �

But fixing this require not only SimpleLogAdapter, but python logging module, or maybe using our own safe logger that do not blow up when feeding them junk data.

Not sure if it worth the time to try to handle this.
Line 1087:         extra = dict(e1=u'Hello', e2='Здра́вствуйте', e3=u'שלום', e4='你好',
Line 1088:                      e5=invalid, e6=u_invalid)
Line 1089:         log = logUtils.SimpleLogAdapter(self._log, extra)
Line 1090:         log.debug("Dobrý večer")


-- 
To view, visit https://gerrit.ovirt.org/48542
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I1930817ade1799b218913348ffa099aab2211ef7
Gerrit-PatchSet: 3
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Milan Zamazal <mzamazal at redhat.com>
Gerrit-Reviewer: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Milan Zamazal <mzamazal at redhat.com>
Gerrit-Reviewer: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: Vinzenz Feenstra <vfeenstr at redhat.com>
Gerrit-Reviewer: Yaniv Bronhaim <ybronhei at redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation at ovirt.org>
Gerrit-HasComments: Yes


More information about the vdsm-patches mailing list