[Python-checkins] r68834 - in python/branches/release30-maint: Lib/logging/__init__.py Lib/logging/handlers.py Misc/NEWS

vinay.sajip python-checkins at python.org
Wed Jan 21 01:26:02 CET 2009


Author: vinay.sajip
Date: Wed Jan 21 01:26:02 2009
New Revision: 68834

Log:
Issue 5013: Fixed bug in FileHandler when delay was set - added fix for RotatingFileHandler and changed header comment slightly.

Modified:
   python/branches/release30-maint/Lib/logging/__init__.py
   python/branches/release30-maint/Lib/logging/handlers.py
   python/branches/release30-maint/Misc/NEWS

Modified: python/branches/release30-maint/Lib/logging/__init__.py
==============================================================================
--- python/branches/release30-maint/Lib/logging/__init__.py	(original)
+++ python/branches/release30-maint/Lib/logging/__init__.py	Wed Jan 21 01:26:02 2009
@@ -1,4 +1,4 @@
-# Copyright 2001-2008 by Vinay Sajip. All Rights Reserved.
+# Copyright 2001-2009 by Vinay Sajip. All Rights Reserved.
 #
 # Permission to use, copy, modify, and distribute this software and its
 # documentation for any purpose and without fee is hereby granted,
@@ -18,7 +18,7 @@
 Logging package for Python. Based on PEP 282 and comments thereto in
 comp.lang.python, and influenced by Apache's log4j system.
 
-Copyright (C) 2001-2008 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2009 Vinay Sajip. All Rights Reserved.
 
 To use, simply 'import logging' and log away!
 """
@@ -43,7 +43,7 @@
 __author__  = "Vinay Sajip <vinay_sajip at red-dove.com>"
 __status__  = "production"
 __version__ = "0.5.0.5"
-__date__    = "24 January 2008"
+__date__    = "20 January 2009"
 
 #---------------------------------------------------------------------------
 #   Miscellaneous module data
@@ -726,7 +726,6 @@
         if strm is None:
             strm = sys.stderr
         self.stream = strm
-        self.formatter = None
 
     def flush(self):
         """
@@ -781,10 +780,12 @@
         self.mode = mode
         self.encoding = encoding
         if delay:
+            #We don't open the stream, but we still need to call the
+            #Handler constructor to set level, formatter, lock etc.
+            Handler.__init__(self)
             self.stream = None
         else:
-            stream = self._open()
-            StreamHandler.__init__(self, stream)
+            StreamHandler.__init__(self, self._open())
 
     def close(self):
         """
@@ -816,8 +817,7 @@
         constructor, open it before calling the superclass's emit.
         """
         if self.stream is None:
-            stream = self._open()
-            StreamHandler.__init__(self, stream)
+            self.stream = self._open()
         StreamHandler.emit(self, record)
 
 #---------------------------------------------------------------------------

Modified: python/branches/release30-maint/Lib/logging/handlers.py
==============================================================================
--- python/branches/release30-maint/Lib/logging/handlers.py	(original)
+++ python/branches/release30-maint/Lib/logging/handlers.py	Wed Jan 21 01:26:02 2009
@@ -1,4 +1,4 @@
-# Copyright 2001-2007 by Vinay Sajip. All Rights Reserved.
+# Copyright 2001-2009 by Vinay Sajip. All Rights Reserved.
 #
 # Permission to use, copy, modify, and distribute this software and its
 # documentation for any purpose and without fee is hereby granted,
@@ -19,9 +19,9 @@
 based on PEP 282 and comments thereto in comp.lang.python, and influenced by
 Apache's log4j system.
 
-Copyright (C) 2001-2008 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2009 Vinay Sajip. All Rights Reserved.
 
-To use, simply 'import logging' and log away!
+To use, simply 'import logging.handlers' and log away!
 """
 
 import logging, socket, os, pickle, struct, time, re
@@ -112,8 +112,8 @@
         """
         Do a rollover, as described in __init__().
         """
-
-        self.stream.close()
+        if self.stream:
+            self.stream.close()
         if self.backupCount > 0:
             for i in range(self.backupCount - 1, 0, -1):
                 sfn = "%s.%d" % (self.baseFilename, i)
@@ -138,6 +138,8 @@
         Basically, see if the supplied record would cause the file to exceed
         the size limit we have.
         """
+        if self.stream is None:                 # delay was set...
+            self.stream = self._open()
         if self.maxBytes > 0:                   # are we rolling over?
             msg = "%s\n" % self.format(record)
             self.stream.seek(0, 2)  #due to non-posix-compliant Windows feature
@@ -302,7 +304,8 @@
         then we have to get a list of matching filenames, sort them and remove
         the one with the oldest suffix.
         """
-        self.stream.close()
+        if self.stream:
+            self.stream.close()
         # get the time that this sequence started at and make it a TimeTuple
         t = self.rolloverAt - self.interval
         if self.utc:

Modified: python/branches/release30-maint/Misc/NEWS
==============================================================================
--- python/branches/release30-maint/Misc/NEWS	(original)
+++ python/branches/release30-maint/Misc/NEWS	Wed Jan 21 01:26:02 2009
@@ -31,7 +31,7 @@
   function no longer attempt to call the __long__ slot to convert an object
   to an integer.  Only the __int__ and __trunc__ slots are examined.
 
-- Issue #4604: Some objects of the I/O library could still be used after 
+- Issue #4604: Some objects of the I/O library could still be used after
   having been closed (for instance, a read() call could return some
   previously buffered data). Patch by Dmitry Vasiliev.
 
@@ -98,6 +98,9 @@
 Library
 -------
 
+- Issue #5013: Fixed a bug in FileHandler which occurred when the delay
+  parameter was set.
+
 - Issue #4842: Always append a trailing 'L' when pickling longs using
   pickle protocol 0.  When reading, the 'L' is optional.
 
@@ -116,8 +119,8 @@
 - Issue #3638: Remove functions from _tkinter module level that depend on
   TkappObject to work with multiple threads.
 
-- Issue #4718: Adapt the wsgiref package so that it actually works with 
-  Python 3.x, in accordance with the `official amendments of the spec 
+- Issue #4718: Adapt the wsgiref package so that it actually works with
+  Python 3.x, in accordance with the `official amendments of the spec
   <http://www.wsgi.org/wsgi/Amendments_1.0>`_.
 
 - Fractions.from_float() no longer loses precision for integers too big to
@@ -132,10 +135,10 @@
 - Issue #4795: inspect.isgeneratorfunction() returns False instead of None when
   the function is not a generator.
 
-- Issue #4702: Throwing a DistutilsPlatformError instead of IOError in case 
-  no MSVC compiler is found under Windows. Original patch by Philip Jenvey. 
+- Issue #4702: Throwing a DistutilsPlatformError instead of IOError in case
+  no MSVC compiler is found under Windows. Original patch by Philip Jenvey.
 
-- Issue #4646: distutils was choking on empty options arg in the setup 
+- Issue #4646: distutils was choking on empty options arg in the setup
   function. Original patch by Thomas Heller.
 
 - Issue #3767: Convert Tk object to string in tkColorChooser.
@@ -410,7 +413,7 @@
 
 - Issue #1210: Fixed imaplib and its documentation.
 
-- Issue #4233: Changed semantic of ``_fileio.FileIO``'s ``close()`` 
+- Issue #4233: Changed semantic of ``_fileio.FileIO``'s ``close()``
   method on file objects with closefd=False. The file descriptor is still
   kept open but the file object behaves like a closed file. The ``FileIO``
   object also got a new readonly attribute ``closefd``.
@@ -554,13 +557,13 @@
   cyclic garbage collection.
 
 - Issue #3668: Fix a memory leak with the "s*" argument parser in
-  PyArg_ParseTuple and friends, which occurred when the argument for "s*" 
+  PyArg_ParseTuple and friends, which occurred when the argument for "s*"
   was correctly parsed but parsing of subsequent arguments failed.
 
 - Issue #3611: An exception __context__ could be cleared in a complex pattern
   involving a __del__ method re-raising an exception.
 
-- Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to 
+- Issue #2534: speed up isinstance() and issubclass() by 50-70%, so as to
   match Python 2.5 speed despite the __instancecheck__ / __subclasscheck__
   mechanism. In the process, fix a bug where isinstance() and issubclass(),
   when given a tuple of classes as second argument, were looking up
@@ -638,7 +641,7 @@
 
 - The deprecation warnings for the camelCase threading API names were removed.
 
-- Issue #3110: multiprocessing fails to compiel on solaris 10 due to missing 
+- Issue #3110: multiprocessing fails to compiel on solaris 10 due to missing
   SEM_VALUE_MAX.
 
 Extension Modules


More information about the Python-checkins mailing list