[ python-Bugs-1524081 ] logging using the SysLog handler fails if locale is set

SourceForge.net noreply at sourceforge.net
Fri Jul 21 01:27:01 CEST 2006


Bugs item #1524081, was opened at 2006-07-17 19:33
Message generated for change (Settings changed) made by vsajip
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1524081&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Mihai Ibanescu (misa)
Assigned to: Nobody/Anonymous (nobody)
Summary: logging using the SysLog handler fails if locale is set

Initial Comment:
This affectes b2 and python 2.4 too.
Initially reported here:
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=198971

Looking at logging/handlers.py:

Line 635:
self.encodePriority(self.facility,                    
            string.lower(record.levelname)), msg)

Line 611 in encodePriority:
priority = self.priority_names[priority]

priority_names is declared on line 527:
    priority_names = {
        "alert":    LOG_ALERT,
        "crit":     LOG_CRIT,
        ...
        "info":     LOG_INFO,
        ...

Now, if one initializes the locale (i.e. 
locale.setlocale(locale.LC_ALL, "")

and then tries to use the logging module, it will fail
with an exception looking kinda like:

  File "/usr/lib64/python2.4/logging/handlers.py", line
627, in encodePriority
    priority = self.priority_names[priority]
KeyError: 'Info'

if they choose LANG=tr_TR.UTF-8

This happens because in that particular locale,
"INFO".lower() != "info"

----------------------------------------------------------------------

>Comment By: Vinay Sajip (vsajip)
Date: 2006-07-20 23:27

Message:
Logged In: YES 
user_id=308438

Fixed by using a dict to map logging level names to syslog
priority level names. This also facilitates usage when
custom logging levels are present.

Fix is checked into Subversion.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1524081&group_id=5470


More information about the Python-bugs-list mailing list