[FIX] locale
bzr revid: christophe@tinyerp.com-20090205134049-suv0tmz2rqdj7rid
This commit is contained in:
parent
47a658c475
commit
eed8260fda
|
@ -87,32 +87,14 @@ LOG_CRITICAL = 'critical'
|
|||
# add new log level below DEBUG
|
||||
logging.DEBUG_RPC = logging.DEBUG - 1
|
||||
|
||||
class UnicodeFormatter(logging.Formatter):
|
||||
def __init__(self, enc, fmt=None, datefmt=None):
|
||||
self._enc = enc
|
||||
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), self._enc)
|
||||
|
||||
def formatException(self, *args, **kwargs):
|
||||
return tools.ustr(logging.Formatter.formatException(self, *args, **kwargs), self._enc)
|
||||
|
||||
def format(self, *args, **kwargs):
|
||||
return tools.ustr(logging.Formatter.format(self, *args, **kwargs), self._enc)
|
||||
|
||||
def init_logger():
|
||||
import os
|
||||
from tools.translate import resetlocale
|
||||
l = resetlocale() or ''
|
||||
enc = '.' in l and l.split('.')[1] or 'utf-8'
|
||||
resetlocale()
|
||||
|
||||
logger = logging.getLogger()
|
||||
# create a format for log messages and dates
|
||||
formatter = UnicodeFormatter(enc, '[%(asctime)s] %(levelname)s:%(name)s:%(message)s', '%a %b %d %Y %H:%M:%S')
|
||||
formatter = logging.Formatter('[%(asctime)s] %(levelname)s:%(name)s:%(message)s')
|
||||
|
||||
logging_to_stdout = False
|
||||
if tools.config['syslog']:
|
||||
|
@ -123,7 +105,7 @@ def init_logger():
|
|||
release.version))
|
||||
else:
|
||||
handler = logging.handlers.SysLogHandler('/dev/log')
|
||||
formatter = UnicodeFormatter(enc, "%s %s" % (release.description, release.version) + ':%(levelname)s:%(name)s:%(message)s')
|
||||
formatter = logging.Formatter("%s %s" % (release.description, release.version) + ':%(levelname)s:%(name)s:%(message)s')
|
||||
|
||||
elif tools.config['logfile']:
|
||||
# LogFile Handler
|
||||
|
@ -175,7 +157,7 @@ def init_logger():
|
|||
|
||||
class Logger(object):
|
||||
def notifyChannel(self, name, level, msg):
|
||||
log = logging.getLogger(name)
|
||||
log = logging.getLogger(tools.ustr(name))
|
||||
|
||||
if level == LOG_DEBUG_RPC and not hasattr(log, level):
|
||||
fct = lambda msg, *args, **kwargs: log.log(logging.DEBUG_RPC, msg, *args, **kwargs)
|
||||
|
|
|
@ -658,7 +658,7 @@ class cache(object):
|
|||
def to_xml(s):
|
||||
return s.replace('&','&').replace('<','<').replace('>','>')
|
||||
|
||||
def ustr(value, fromenc='utf-8'):
|
||||
def ustr(value):
|
||||
"""This method is similar to the builtin `str` method, except
|
||||
it will return Unicode string.
|
||||
|
||||
|
@ -677,7 +677,7 @@ def ustr(value, fromenc='utf-8'):
|
|||
if not isinstance(value, str):
|
||||
value = str(value)
|
||||
|
||||
return unicode(value, fromenc)
|
||||
return unicode(value, 'utf-8')
|
||||
|
||||
def exception_to_unicode(e):
|
||||
if hasattr(e, 'message'):
|
||||
|
|
Loading…
Reference in New Issue