[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
|
||||
|
||||
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']:
|
||||
# SysLog Handler
|
||||
if os.name == 'nt':
|
||||
sysloghandler = logging.handlers.NTEventLogHandler("%s %s" %
|
||||
handler = logging.handlers.NTEventLogHandler("%s %s" %
|
||||
(release.description,
|
||||
release.version))
|
||||
else:
|
||||
sysloghandler = logging.handlers.SysLogHandler('/dev/log')
|
||||
formatter = logging.Formatter('%(application)s:%(uncoloredlevelname)s:%(name)s:%(message)s')
|
||||
sysloghandler.setFormatter(formatter)
|
||||
logger.addHandler(sysloghandler)
|
||||
handler = logging.handlers.SysLogHandler('/dev/log')
|
||||
formatter = logging.Formatter("%s %s" % (release.description, release.version) + ':%(levelname)s:%(name)s:%(message)s')
|
||||
|
||||
# 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['logfile']:
|
||||
elif tools.config['logfile']:
|
||||
# LogFile Handler
|
||||
logf = tools.config['logfile']
|
||||
try:
|
||||
|
@ -216,14 +214,6 @@ def init_logger():
|
|||
|
||||
|
||||
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):
|
||||
log = logging.getLogger(name)
|
||||
|
||||
|
@ -231,19 +221,14 @@ class Logger(object):
|
|||
fct = lambda msg, *args, **kwargs: log.log(logging.DEBUG_RPC, msg, *args, **kwargs)
|
||||
setattr(log, LOG_DEBUG_RPC, fct)
|
||||
|
||||
extra = {
|
||||
'uncoloredlevelname': self.uncoloredlevelname(level),
|
||||
'application' : "%s %s" % (release.description, release.version),
|
||||
}
|
||||
|
||||
level_method = getattr(log, level)
|
||||
|
||||
result = tools.ustr(msg).strip().split('\n')
|
||||
if len(result)>1:
|
||||
for idx, s in enumerate(result):
|
||||
level_method('[%02d]: %s' % (idx+1, s,), extra=extra)
|
||||
level_method('[%02d]: %s' % (idx+1, s,))
|
||||
elif result:
|
||||
level_method(result[0], extra=extra)
|
||||
level_method(result[0])
|
||||
|
||||
import tools
|
||||
init_logger()
|
||||
|
|
|
@ -179,6 +179,7 @@ class configmanager(object):
|
|||
|
||||
(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_out and (not opt.db_name)), "the i18n-export option cannot be used without the database (-d) option"
|
||||
|
||||
|
|
Loading…
Reference in New Issue