[FIX] all loggers are exclusives -> python 2.4 compatible
bzr revid: christophe@cobalt-20081229102451-m9my1c0dezd7wk8q
This commit is contained in:
parent
55a598d504
commit
b86bfc4e61
|
@ -154,22 +154,20 @@ def init_logger():
|
||||||
import os
|
import os
|
||||||
|
|
||||||
logger = logging.getLogger()
|
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')
|
||||||
|
|
||||||
if tools.config['syslog']:
|
if tools.config['syslog']:
|
||||||
# SysLog Handler
|
# SysLog Handler
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
sysloghandler = logging.handlers.NTEventLogHandler("%s %s" %
|
handler = logging.handlers.NTEventLogHandler("%s %s" %
|
||||||
(release.description,
|
(release.description,
|
||||||
release.version))
|
release.version))
|
||||||
else:
|
else:
|
||||||
sysloghandler = logging.handlers.SysLogHandler('/dev/log')
|
handler = logging.handlers.SysLogHandler('/dev/log')
|
||||||
formatter = logging.Formatter('%(application)s:%(uncoloredlevelname)s:%(name)s:%(message)s')
|
formatter = logging.Formatter("%s %s" % (release.description, release.version) + ':%(levelname)s:%(name)s:%(message)s')
|
||||||
sysloghandler.setFormatter(formatter)
|
|
||||||
logger.addHandler(sysloghandler)
|
|
||||||
|
|
||||||
# create a format for log messages and dates
|
elif tools.config['logfile']:
|
||||||
formatter = logging.Formatter('[%(asctime)s] %(levelname)s:%(name)s:%(message)s', '%a %b %d %Y %H:%M:%S')
|
|
||||||
if tools.config['logfile']:
|
|
||||||
# LogFile Handler
|
# LogFile Handler
|
||||||
logf = tools.config['logfile']
|
logf = tools.config['logfile']
|
||||||
try:
|
try:
|
||||||
|
@ -216,14 +214,6 @@ def init_logger():
|
||||||
|
|
||||||
|
|
||||||
class Logger(object):
|
class Logger(object):
|
||||||
def uncoloredlevelname(self, level):
|
|
||||||
# The level'names are globals to all loggers, so we must strip-off the
|
|
||||||
# color formatting for some specific logger (i.e: syslog)
|
|
||||||
levelname = logging.getLevelName(getattr(logging, level.upper(), 0))
|
|
||||||
if levelname.startswith("\x1b["):
|
|
||||||
return levelname[10:-4]
|
|
||||||
return levelname
|
|
||||||
|
|
||||||
def notifyChannel(self, name, level, msg):
|
def notifyChannel(self, name, level, msg):
|
||||||
log = logging.getLogger(name)
|
log = logging.getLogger(name)
|
||||||
|
|
||||||
|
@ -231,19 +221,14 @@ class Logger(object):
|
||||||
fct = lambda msg, *args, **kwargs: log.log(logging.DEBUG_RPC, msg, *args, **kwargs)
|
fct = lambda msg, *args, **kwargs: log.log(logging.DEBUG_RPC, msg, *args, **kwargs)
|
||||||
setattr(log, LOG_DEBUG_RPC, fct)
|
setattr(log, LOG_DEBUG_RPC, fct)
|
||||||
|
|
||||||
extra = {
|
|
||||||
'uncoloredlevelname': self.uncoloredlevelname(level),
|
|
||||||
'application' : "%s %s" % (release.description, release.version),
|
|
||||||
}
|
|
||||||
|
|
||||||
level_method = getattr(log, level)
|
level_method = getattr(log, level)
|
||||||
|
|
||||||
result = tools.ustr(msg).strip().split('\n')
|
result = tools.ustr(msg).strip().split('\n')
|
||||||
if len(result)>1:
|
if len(result)>1:
|
||||||
for idx, s in enumerate(result):
|
for idx, s in enumerate(result):
|
||||||
level_method('[%02d]: %s' % (idx+1, s,), extra=extra)
|
level_method('[%02d]: %s' % (idx+1, s,))
|
||||||
elif result:
|
elif result:
|
||||||
level_method(result[0], extra=extra)
|
level_method(result[0])
|
||||||
|
|
||||||
import tools
|
import tools
|
||||||
init_logger()
|
init_logger()
|
||||||
|
|
|
@ -179,6 +179,7 @@ class configmanager(object):
|
||||||
|
|
||||||
(opt, args) = parser.parse_args()
|
(opt, args) = parser.parse_args()
|
||||||
|
|
||||||
|
assert not (bool(opt.syslog) and bool(opt.logfile)), "the syslog and logfile options are exclusive"
|
||||||
assert not (opt.translate_in and (not opt.language or not opt.db_name)), "the i18n-import option cannot be used without the language (-l) and the database (-d) options"
|
assert not (opt.translate_in and (not opt.language or not opt.db_name)), "the i18n-import option cannot be used without the language (-l) and the database (-d) options"
|
||||||
assert not (opt.translate_out and (not opt.db_name)), "the i18n-export option cannot be used without the database (-d) option"
|
assert not (opt.translate_out and (not opt.db_name)), "the i18n-export option cannot be used without the database (-d) option"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue