[FIX] unicodify the logger

lp bug: https://launchpad.net/bugs/325259 fixed

bzr revid: christophe@tinyerp.com-20090204172700-3ivskfwcofpma74t
This commit is contained in:
Christophe Simonis 2009-02-04 18:27:00 +01:00
parent 2b7b9ebc61
commit c0a85c932b
2 changed files with 27 additions and 5 deletions

View File

@ -87,12 +87,30 @@ LOG_CRITICAL = 'critical'
# add new log level below DEBUG
logging.DEBUG_RPC = logging.DEBUG - 1
class UnicodeFormatter(logging.Formatter):
def __init__(self, fmt=None, datefmt=None):
logging.Formatter.__init__(self, fmt, datefmt)
self._fmt = tools.ustr(self._fmt)
if self.datefmt is not None:
self.datefmt = tools.ustr(self.datefmt)
def formatTime(self, *args, **kwargs):
return tools.ustr(logging.Formatter.formatTime(self, *args, **kwargs))
def formatException(self, *args, **kwargs):
return tools.ustr(logging.Formatter.formatException(self, *args, **kwargs))
def format(self, *args, **kwargs):
return tools.ustr(logging.Formatter.format(self, *args, **kwargs))
def init_logger():
import os
from tools.translate import resetlocale
resetlocale()
logger = logging.getLogger()
# create a format for log messages and dates
formatter = logging.Formatter('[%(asctime)s] %(levelname)s:%(name)s:%(message)s', '%a %b %d %Y %H:%M:%S')
formatter = UnicodeFormatter('[%(asctime)s] %(levelname)s:%(name)s:%(message)s', '%a %b %d %Y %H:%M:%S')
logging_to_stdout = False
if tools.config['syslog']:
@ -103,7 +121,7 @@ def init_logger():
release.version))
else:
handler = logging.handlers.SysLogHandler('/dev/log')
formatter = logging.Formatter("%s %s" % (release.description, release.version) + ':%(levelname)s:%(name)s:%(message)s')
formatter = UnicodeFormatter("%s %s" % (release.description, release.version) + ':%(levelname)s:%(name)s:%(message)s')
elif tools.config['logfile']:
# LogFile Handler

View File

@ -564,9 +564,7 @@ def trans_load_data(db_name, fileobj, fileformat, lang, strict=False, lang_name=
try:
lang_obj.create(cr, uid, lang_info)
finally:
# locale.resetlocale is bugged with some locales.
# we need to normalize the result of locale.getdefaultlocale()
locale.setlocale(locale.LC_ALL, locale.normalize(locale._build_localename(locale.getdefaultlocale())))
resetlocale()
# now, the serious things: we read the language file
@ -660,5 +658,11 @@ def trans_load_data(db_name, fileobj, fileformat, lang, strict=False, lang_name=
logger.notifyChannel("i18n", netsvc.LOG_ERROR, "couldn't read translation file %s" % (filename,))
def resetlocale():
# locale.resetlocale is bugged with some locales.
# we need to normalize the result of locale.getdefaultlocale()
locale.setlocale(locale.LC_ALL, locale.normalize(locale._build_localename(locale.getdefaultlocale())))
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: