Inconsistent behaviour when unicode args used for logging

Bug #1563295 reported by Konstantin
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
oslo.log
Fix Released
Undecided
Andrey Volkov

Bug Description

When i used unicode args for log message, i got UnicodeDecodeError
If replace using oslo_log to logging from std python library, logging works fine

[1] Sample script, logging with oslo_log module http://paste.openstack.org/show/492234/
[2] Sample script, logging with Python logging module http://paste.openstack.org/show/492234/
[3] Sample file with unicode data http://paste.openstack.org/show/492235/

How to reproduce:

1 Save [3] as 'text.txt'
2 Run [1]

Expected result:

File log.txt contains
"жлдоыфв
фыжваофждыов"

Actual result:

Exception "UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
Logged from file oslo_test.py, line 9"

$ pip freeze|grep oslo.log

oslo.log==3.2.0

Revision history for this message
Konstantin (ksnihyr) wrote :
description: updated
description: updated
Revision history for this message
Andrey Volkov (avolkov) wrote :

Can be easily reproduced with:
from oslo_log import log as logging
LOG = logging.getLogger(__name__)
LOG.info("Oslo Logging %s", u'\u2622'.encode('utf8'))

The issue is related to implicit decoding of logging arguments due
_ensure_unicode for message:
https://github.com/openstack/oslo.log/blob/master/oslo_log/log.py#L129

Changed in oslo.log:
status: New → Confirmed
Andrey Volkov (avolkov)
no longer affects: nova
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to oslo.log (master)

Fix proposed to branch: master
Review: https://review.openstack.org/323677

Changed in oslo.log:
assignee: nobody → Andrey Volkov (avolkov)
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslo.log (master)

Reviewed: https://review.openstack.org/323677
Committed: https://git.openstack.org/cgit/openstack/oslo.log/commit/?id=991d8f0a125b7f421c597c0a3af7df9b10c4de19
Submitter: Jenkins
Branch: master

commit 991d8f0a125b7f421c597c0a3af7df9b10c4de19
Author: Andrey Volkov <email address hidden>
Date: Tue May 31 20:14:40 2016 +0300

    Make available to log encoded strings as arguments

    Pure python logging library allows to log encoded strings
    but in oslo_log it causes UnicodeDecodeError for arguments
    which contains unicode symbols.

    Changes add additional check whether all arguments can be converted to
    unicode. If it isn't possible then leave it as is.

    Change-Id: I76e75c35a74b146fae52c0ea60156e1cf78540e7
    Closes-Bug: #1563295

Changed in oslo.log:
status: In Progress → Fix Released
Revision history for this message
Davanum Srinivas (DIMS) (dims-v) wrote : Fix included in openstack/oslo.log 3.9.0

This issue was fixed in the openstack/oslo.log 3.9.0 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to oslo.log (stable/mitaka)

Fix proposed to branch: stable/mitaka
Review: https://review.openstack.org/371582

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslo.log (stable/mitaka)

Reviewed: https://review.openstack.org/371582
Committed: https://git.openstack.org/cgit/openstack/oslo.log/commit/?id=a2e7f6597ee7f57936cdf2b760068e556cad9a59
Submitter: Jenkins
Branch: stable/mitaka

commit a2e7f6597ee7f57936cdf2b760068e556cad9a59
Author: Andrey Volkov <email address hidden>
Date: Tue May 31 20:14:40 2016 +0300

    Make available to log encoded strings as arguments

    Pure python logging library allows to log encoded strings
    but in oslo_log it causes UnicodeDecodeError for arguments
    which contains unicode symbols.

    Changes add additional check whether all arguments can be converted to
    unicode. If it isn't possible then leave it as is.

    Change-Id: I76e75c35a74b146fae52c0ea60156e1cf78540e7
    Closes-Bug: #1563295

tags: added: in-stable-mitaka
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.