[Python-checkins] r76498 - python/trunk/Lib/logging/__init__.py

vinay.sajip python-checkins at python.org
Tue Nov 24 16:53:25 CET 2009


Author: vinay.sajip
Date: Tue Nov 24 16:53:25 2009
New Revision: 76498
Log:
Made logging classes new-style and added name property to handlers.
Modified:
 python/trunk/Lib/logging/__init__.py
Modified: python/trunk/Lib/logging/__init__.py
==============================================================================
--- python/trunk/Lib/logging/__init__.py	(original)
+++ python/trunk/Lib/logging/__init__.py	Tue Nov 24 16:53:25 2009
@@ -46,8 +46,8 @@
 
 __author__ = "Vinay Sajip <vinay_sajip at red-dove.com>"
 __status__ = "production"
-__version__ = "0.5.0.9"
-__date__ = "09 October 2009"
+__version__ = "0.5.1.0"
+__date__ = "24 November 2009"
 
 #---------------------------------------------------------------------------
 # Miscellaneous module data
@@ -196,9 +196,9 @@
 
 #
 #_lock is used to serialize access to shared data structures in this module.
-#This needs to be an RLock because fileConfig() creates Handlers and so
-#might arbitrary user threads. Since Handler.__init__() updates the shared
-#dictionary _handlers, it needs to acquire the lock. But if configuring,
+#This needs to be an RLock because fileConfig() creates and configures
+#Handlers, and so might arbitrary user threads. Since Handler code updates the
+#shared dictionary _handlers, it needs to acquire the lock. But if configuring,
 #the lock would already have been acquired - so we need an RLock.
 #The same argument applies to Loggers and Manager.loggerDict.
 #
@@ -227,7 +227,7 @@
 # The logging record
 #---------------------------------------------------------------------------
 
-class LogRecord:
+class LogRecord(object):
 """
 A LogRecord instance represents an event being logged.
 
@@ -335,7 +335,7 @@
 # Formatter classes and functions
 #---------------------------------------------------------------------------
 
-class Formatter:
+class Formatter(object):
 """
 Formatter instances are used to convert a LogRecord to text.
 
@@ -467,7 +467,7 @@
 #
 _defaultFormatter = Formatter()
 
-class BufferingFormatter:
+class BufferingFormatter(object):
 """
 A formatter suitable for formatting a number of records.
 """
@@ -509,7 +509,7 @@
 # Filter classes and functions
 #---------------------------------------------------------------------------
 
-class Filter:
+class Filter(object):
 """
 Filter instances are used to perform arbitrary filtering of LogRecords.
 
@@ -546,7 +546,7 @@
 return 0
 return (record.name[self.nlen] == ".")
 
-class Filterer:
+class Filterer(object):
 """
 A base class for loggers and handlers which allows them to share
 common code.
@@ -590,7 +590,7 @@
 # Handler classes and functions
 #---------------------------------------------------------------------------
 
-_handlers = {} #repository of handlers (for flushing when shutdown called)
+_handlers = {} #map of handler names to handlers
 _handlerList = [] # added to allow handlers to be removed in reverse of order initialized
 
 class Handler(Filterer):
@@ -608,17 +608,33 @@
 and the filter list to empty.
 """
 Filterer.__init__(self)
+ self._name = None
 self.level = _checkLevel(level)
 self.formatter = None
 #get the module data lock, as we're updating a shared structure.
 _acquireLock()
 try: #unlikely to raise an exception, but you never know...
- _handlers[self] = 1
 _handlerList.insert(0, self)
 finally:
 _releaseLock()
 self.createLock()
 
+ def get_name(self):
+ return self._name
+
+ def set_name(self, name):
+ _acquireLock()
+ try:
+ if self._name in _handlers:
+ del _handlers[self._name]
+ self._name = name
+ if name:
+ _handlers[name] = self
+ finally:
+ _releaseLock()
+
+ name = property(get_name, set_name)
+
 def createLock(self):
 """
 Acquire a thread lock for serializing access to the underlying I/O.
@@ -716,7 +732,8 @@
 #get the module data lock, as we're updating a shared structure.
 _acquireLock()
 try: #unlikely to raise an exception, but you never know...
- del _handlers[self]
+ if self._name and self._name in _handlers:
+ del _handlers[self._name]
 _handlerList.remove(self)
 finally:
 _releaseLock()
@@ -869,7 +886,7 @@
 # Manager classes and functions
 #---------------------------------------------------------------------------
 
-class PlaceHolder:
+class PlaceHolder(object):
 """
 PlaceHolder instances are used in the Manager logger hierarchy to take
 the place of nodes for which no loggers have been defined. This class is
@@ -916,7 +933,7 @@
 
 return _loggerClass
 
-class Manager:
+class Manager(object):
 """
 There is [under normal circumstances] just one Manager instance, which
 holds the hierarchy of loggers.
@@ -1269,7 +1286,7 @@
 
 _loggerClass = Logger
 
-class LoggerAdapter:
+class LoggerAdapter(object):
 """
 An adapter for loggers which makes it easier to specify contextual
 information in logging output.


More information about the Python-checkins mailing list

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