[Python-checkins] python/dist/src/Lib/logging __init__.py, 1.11, 1.12

vsajip at users.sourceforge.net vsajip at users.sourceforge.net
Fri Feb 20 08:18:39 EST 2004


Update of /cvsroot/python/python/dist/src/Lib/logging
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12019

Modified Files:
	__init__.py 
Log Message:
Copyright year & version number/version date changes.
Exception traceback text is now cached.
Closing a handler now removes it from the internal _handlers list.
Handlers now chain to Handler.close() from their close() methods.
Exception info can be passed as a tuple in exc_info.
shutdown() is registered to be called at application exit.

Index: __init__.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/logging/__init__.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** __init__.py	27 Jun 2003 21:43:39 -0000	1.11
--- __init__.py	20 Feb 2004 13:18:36 -0000	1.12
***************
*** 22,26 ****
  information is not available unless 'sys._getframe()' is.
  
! Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
  
  To use, simply 'import logging' and log away!
--- 22,26 ----
  information is not available unless 'sys._getframe()' is.
  
! Copyright (C) 2001-2004 Vinay Sajip. All Rights Reserved.
  
  To use, simply 'import logging' and log away!
***************
*** 37,42 ****
  __author__  = "Vinay Sajip <vinay_sajip at red-dove.com>"
  __status__  = "beta"
! __version__ = "0.4.8.1"
! __date__    = "26 June 2003"
  
  #---------------------------------------------------------------------------
--- 37,42 ----
  __author__  = "Vinay Sajip <vinay_sajip at red-dove.com>"
  __status__  = "beta"
! __version__ = "0.4.9"
! __date__    = "20 February 2004"
  
  #---------------------------------------------------------------------------
***************
*** 199,202 ****
--- 199,203 ----
              self.module = "Unknown module"
          self.exc_info = exc_info
+         self.exc_text = None      # used to cache the traceback text
          self.lineno = lineno
          self.created = ct
***************
*** 365,371 ****
          s = self._fmt % record.__dict__
          if record.exc_info:
              if s[-1] != "\n":
                  s = s + "\n"
!             s = s + self.formatException(record.exc_info)
          return s
  
--- 366,377 ----
          s = self._fmt % record.__dict__
          if record.exc_info:
+             # Cache the traceback text to avoid converting it multiple times
+             # (it's constant anyway)
+             if not record.exc_text:
+                 record.exc_text = self.formatException(record.exc_info)
+         if record.exc_text:
              if s[-1] != "\n":
                  s = s + "\n"
!             s = s + record.exc_text
          return s
  
***************
*** 614,621 ****
          Tidy up any resources used by the handler.
  
!         This version does nothing and is intended to be implemented by
!         subclasses.
          """
!         pass
  
      def handleError(self, record):
--- 620,634 ----
          Tidy up any resources used by the handler.
  
!         This version does removes the handler from an internal list
!         of handlers which is closed when shutdown() is called. Subclasses
!         should ensure that this gets called from overridden close()
!         methods.
          """
!         #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]
!         finally:
!             _releaseLock()
  
      def handleError(self, record):
***************
*** 701,704 ****
--- 714,718 ----
          """
          self.stream.close()
+         StreamHandler.close(self)
  
  #---------------------------------------------------------------------------
***************
*** 990,994 ****
              fn, lno = "<unknown file>", 0
          if exc_info:
!             exc_info = sys.exc_info()
          record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info)
          self.handle(record)
--- 1004,1009 ----
              fn, lno = "<unknown file>", 0
          if exc_info:
!             if type(exc_info) != types.TupleType:
!                 exc_info = sys.exc_info()
          record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info)
          self.handle(record)
***************
*** 1195,1196 ****
--- 1210,1224 ----
          h.flush()
          h.close()
+ 
+ #Let's try and shutdown automatically on application exit...
+ try:
+     import atexit
+     atexit.register(shutdown)
+ except ImportError: # for Python versions < 2.0
+     def exithook(status, old_exit=sys.exit):
+         try:
+             shutdown()
+         finally:
+             old_exit(status)
+ 
+     sys.exit = exithook




More information about the Python-checkins mailing list