[Python-checkins] r84936 - in python/branches/py3k: Doc/library/logging.rst Lib/logging/__init__.py Lib/logging/handlers.py Lib/test/test_logging.py Misc/NEWS

vinay.sajip python-checkins at python.org
Tue Sep 21 13:25:40 CEST 2010


Author: vinay.sajip
Date: Tue Sep 21 13:25:39 2010
New Revision: 84936
Log:
Added some methods to LoggerAdapter, and updated documentation.
Modified:
 python/branches/py3k/Doc/library/logging.rst
 python/branches/py3k/Lib/logging/__init__.py
 python/branches/py3k/Lib/logging/handlers.py
 python/branches/py3k/Lib/test/test_logging.py
 python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Doc/library/logging.rst
==============================================================================
--- python/branches/py3k/Doc/library/logging.rst	(original)
+++ python/branches/py3k/Doc/library/logging.rst	Tue Sep 21 13:25:39 2010
@@ -2599,8 +2599,8 @@
 .. method:: flush()
 
 For a :class:`MemoryHandler`, flushing means just sending the buffered
- records to the target, if there is one. Override if you want different
- behavior.
+ records to the target, if there is one. The buffer is also cleared when
+ this happens. Override if you want different behavior.
 
 
 .. method:: setTarget(target)
@@ -2972,15 +2972,18 @@
 'extra'. The return value is a (*msg*, *kwargs*) tuple which has the
 (possibly modified) versions of the arguments passed in.
 
-In addition to the above, :class:`LoggerAdapter` supports all the logging
+In addition to the above, :class:`LoggerAdapter` supports the following
 methods of :class:`Logger`, i.e. :meth:`debug`, :meth:`info`, :meth:`warning`,
-:meth:`error`, :meth:`exception`, :meth:`critical` and :meth:`log`. These
-methods have the same signatures as their counterparts in :class:`Logger`, so
-you can use the two types of instances interchangeably.
+:meth:`error`, :meth:`exception`, :meth:`critical`, :meth:`log`,
+:meth:`isEnabledFor`, :meth:`getEffectiveLevel`, :meth:`setLevel`,
+:meth:`hasHandlers`. These methods have the same signatures as their
+counterparts in :class:`Logger`, so you can use the two types of instances
+interchangeably.
 
 .. versionchanged:: 3.2
- The :meth:`isEnabledFor` method was added to :class:`LoggerAdapter`. This
- method delegates to the underlying logger.
+ The :meth:`isEnabledFor`, :meth:`getEffectiveLevel`, :meth:`setLevel` and
+ :meth:`hasHandlers` methods were added to :class:`LoggerAdapter`. These
+ methods delegate to the underlying logger.
 
 
 Thread Safety
Modified: python/branches/py3k/Lib/logging/__init__.py
==============================================================================
--- python/branches/py3k/Lib/logging/__init__.py	(original)
+++ python/branches/py3k/Lib/logging/__init__.py	Tue Sep 21 13:25:39 2010
@@ -1400,6 +1400,8 @@
 msg, kwargs = self.process(msg, kwargs)
 self.logger.warning(msg, *args, **kwargs)
 
+ warn = warning
+
 def error(self, msg, *args, **kwargs):
 """
 Delegate an error call to the underlying logger, after adding
@@ -1433,12 +1435,24 @@
 msg, kwargs = self.process(msg, kwargs)
 self.logger.log(level, msg, *args, **kwargs)
 
+ def setLevel(self, level):
+ """
+ Set the specified level on the underlying logger.
+ """
+ self.logger.setLevel(level)
+
 def isEnabledFor(self, level):
 """
 See if the underlying logger is enabled for the specified level.
 """
 return self.logger.isEnabledFor(level)
 
+ def getEffectiveLevel(self):
+ """
+ Get the effective level for the underlying logger.
+ """
+ return self.logger.getEffectiveLevel()
+
 def hasHandlers(self):
 """
 See if the underlying logger has any handlers.
Modified: python/branches/py3k/Lib/logging/handlers.py
==============================================================================
--- python/branches/py3k/Lib/logging/handlers.py	(original)
+++ python/branches/py3k/Lib/logging/handlers.py	Tue Sep 21 13:25:39 2010
@@ -1131,6 +1131,8 @@
 For a MemoryHandler, flushing means just sending the buffered
 records to the target, if there is one. Override if you want
 different behaviour.
+
+ The record buffer is also cleared by this operation.
 """
 if self.target:
 for record in self.buffer:
Modified: python/branches/py3k/Lib/test/test_logging.py
==============================================================================
--- python/branches/py3k/Lib/test/test_logging.py	(original)
+++ python/branches/py3k/Lib/test/test_logging.py	Tue Sep 21 13:25:39 2010
@@ -154,7 +154,7 @@
 
 ERR = logging.getLogger("ERR")
 ERR.setLevel(logging.ERROR)
- INF = logging.getLogger("INF")
+ INF = logging.LoggerAdapter(logging.getLogger("INF"), {})
 INF.setLevel(logging.INFO)
 DEB = logging.getLogger("DEB")
 DEB.setLevel(logging.DEBUG)
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Tue Sep 21 13:25:39 2010
@@ -58,6 +58,10 @@
 Library
 -------
 
+- logging: hasHandlers method was added to Logger, and isEnabledFor,
+ getEffectiveLevel, hasHandlers and setLevel were added to LoggerAdapter.
+ LoggerAdapter was introduced into the unit tests for logging.
+
 - Issue #1686: Fix string.Template when overriding the pattern attribute.
 
 - Issue #9854: SocketIO objects now observe the RawIOBase interface in


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /