[REF] logging: removed deprecated Logger class.
bzr revid: vmt@openerp.com-20130326154006-s19z7aem22qeboo0
This commit is contained in:
parent
7fea92de51
commit
d96ec9c680
|
@ -33,67 +33,6 @@ LOG_CRITICAL = 'critical'
|
||||||
logging.TEST = logging.INFO - 5
|
logging.TEST = logging.INFO - 5
|
||||||
logging.addLevelName(logging.TEST, 'TEST')
|
logging.addLevelName(logging.TEST, 'TEST')
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class Logger(object):
|
|
||||||
def __init__(self):
|
|
||||||
_logger.warning(
|
|
||||||
"The netsvc.Logger API shouldn't be used anymore, please "
|
|
||||||
"use the standard `logging.getLogger` API instead.")
|
|
||||||
super(Logger, self).__init__()
|
|
||||||
|
|
||||||
def notifyChannel(self, name, level, msg):
|
|
||||||
_logger.warning(
|
|
||||||
"notifyChannel API shouldn't be used anymore, please use "
|
|
||||||
"the standard `logging` module instead.")
|
|
||||||
from service import common
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__ + '.deprecated.' + ustr(name))
|
|
||||||
|
|
||||||
if level in [LOG_TEST] and not hasattr(log, level):
|
|
||||||
fct = lambda msg, *args, **kwargs: log.log(getattr(logging, level.upper()), msg, *args, **kwargs)
|
|
||||||
setattr(log, level, fct)
|
|
||||||
|
|
||||||
|
|
||||||
level_method = getattr(log, level)
|
|
||||||
|
|
||||||
if isinstance(msg, Exception):
|
|
||||||
msg = exception_to_unicode(msg)
|
|
||||||
|
|
||||||
try:
|
|
||||||
msg = ustr(msg).strip()
|
|
||||||
if level in (LOG_ERROR, LOG_CRITICAL): # and tools.config.get_misc('debug','env_info',False):
|
|
||||||
msg = common.exp_get_server_environment() + "\n" + msg
|
|
||||||
|
|
||||||
result = msg.split('\n')
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
result = msg.strip().split('\n')
|
|
||||||
try:
|
|
||||||
if len(result)>1:
|
|
||||||
for idx, s in enumerate(result):
|
|
||||||
level_method('[%02d]: %s' % (idx+1, s,))
|
|
||||||
elif result:
|
|
||||||
level_method(result[0])
|
|
||||||
except IOError:
|
|
||||||
# TODO: perhaps reset the logger streams?
|
|
||||||
#if logrotate closes our files, we end up here..
|
|
||||||
pass
|
|
||||||
except Exception:
|
|
||||||
# better ignore the exception and carry on..
|
|
||||||
pass
|
|
||||||
|
|
||||||
def set_loglevel(self, level, logger=None):
|
|
||||||
if logger is not None:
|
|
||||||
log = logging.getLogger(str(logger))
|
|
||||||
else:
|
|
||||||
log = logging.getLogger()
|
|
||||||
log.setLevel(logging.INFO) # make sure next msg is printed
|
|
||||||
log.info("Log level changed to %s" % logging.getLevelName(level))
|
|
||||||
log.setLevel(level)
|
|
||||||
|
|
||||||
def shutdown(self):
|
|
||||||
logging.shutdown()
|
|
||||||
|
|
||||||
# TODO get_encodings, ustr and exception_to_unicode were originally from tools.misc.
|
# TODO get_encodings, ustr and exception_to_unicode were originally from tools.misc.
|
||||||
# There are here until we refactor tools so that this module doesn't depends on tools.
|
# There are here until we refactor tools so that this module doesn't depends on tools.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue