Commit 212b590e authored by Vinay Sajip's avatar Vinay Sajip

logging: Updated LoggerAdapter implementation.

parent c84f0169
...@@ -1376,64 +1376,64 @@ class LoggerAdapter(object): ...@@ -1376,64 +1376,64 @@ class LoggerAdapter(object):
kwargs["extra"] = self.extra kwargs["extra"] = self.extra
return msg, kwargs return msg, kwargs
#
# Boilerplate convenience methods
#
def debug(self, msg, *args, **kwargs): def debug(self, msg, *args, **kwargs):
""" """
Delegate a debug call to the underlying logger, after adding Delegate a debug call to the underlying logger.
contextual information from this adapter instance.
""" """
msg, kwargs = self.process(msg, kwargs) self.log(DEBUG, msg, *args, **kwargs)
self.logger.debug(msg, *args, **kwargs)
def info(self, msg, *args, **kwargs): def info(self, msg, *args, **kwargs):
""" """
Delegate an info call to the underlying logger, after adding Delegate an info call to the underlying logger.
contextual information from this adapter instance.
""" """
msg, kwargs = self.process(msg, kwargs) self.log(INFO, msg, *args, **kwargs)
self.logger.info(msg, *args, **kwargs)
def warning(self, msg, *args, **kwargs): def warning(self, msg, *args, **kwargs):
""" """
Delegate a warning call to the underlying logger, after adding Delegate a warning call to the underlying logger.
contextual information from this adapter instance.
""" """
msg, kwargs = self.process(msg, kwargs) self.log(WARNING, msg, *args, **kwargs)
self.logger.warning(msg, *args, **kwargs)
warn = warning warn = warning
def error(self, msg, *args, **kwargs): def error(self, msg, *args, **kwargs):
""" """
Delegate an error call to the underlying logger, after adding Delegate an error call to the underlying logger.
contextual information from this adapter instance.
""" """
msg, kwargs = self.process(msg, kwargs) self.log(ERROR, msg, *args, **kwargs)
self.logger.error(msg, *args, **kwargs)
def exception(self, msg, *args, **kwargs): def exception(self, msg, *args, **kwargs):
""" """
Delegate an exception call to the underlying logger, after adding Delegate an exception call to the underlying logger.
contextual information from this adapter instance.
""" """
msg, kwargs = self.process(msg, kwargs)
kwargs["exc_info"] = 1 kwargs["exc_info"] = 1
self.logger.error(msg, *args, **kwargs) self.log(ERROR, msg, *args, **kwargs)
def critical(self, msg, *args, **kwargs): def critical(self, msg, *args, **kwargs):
""" """
Delegate a critical call to the underlying logger, after adding Delegate a critical call to the underlying logger.
contextual information from this adapter instance.
""" """
msg, kwargs = self.process(msg, kwargs) self.log(CRITICAL, msg, *args, **kwargs)
self.logger.critical(msg, *args, **kwargs)
def log(self, level, msg, *args, **kwargs): def log(self, level, msg, *args, **kwargs):
""" """
Delegate a log call to the underlying logger, after adding Delegate a log call to the underlying logger, after adding
contextual information from this adapter instance. contextual information from this adapter instance.
""" """
if self.isEnabledFor(level):
msg, kwargs = self.process(msg, kwargs) msg, kwargs = self.process(msg, kwargs)
self.logger.log(level, msg, *args, **kwargs) self.logger._log(level, msg, args, **kwargs)
def isEnabledFor(self, level):
"""
Is this logger enabled for level 'level'?
"""
if self.logger.manager.disable >= level:
return False
return level >= self.getEffectiveLevel()
def setLevel(self, level): def setLevel(self, level):
""" """
......
...@@ -58,6 +58,9 @@ Core and Builtins ...@@ -58,6 +58,9 @@ Core and Builtins
Library Library
------- -------
- logging: Changed LoggerAdapter implementation internally, to make it
easier to subclass in a useful way.
- logging: hasHandlers method was added to Logger, and isEnabledFor, - logging: hasHandlers method was added to Logger, and isEnabledFor,
getEffectiveLevel, hasHandlers and setLevel were added to LoggerAdapter. getEffectiveLevel, hasHandlers and setLevel were added to LoggerAdapter.
LoggerAdapter was introduced into the unit tests for logging. LoggerAdapter was introduced into the unit tests for logging.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment