summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-01-24 16:21:45 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-01-24 16:21:45 (GMT)
commite7a15bb808f2118920fed0b5949f821940cf7416 (patch)
tree5b7015f62adf9b7c934f3b9aa83e80e5d7efa929 /Lib/logging
parente83ebd9ab10adc43b0e6368c6985a4a90a85747f (diff)
downloadcpython-e7a15bb808f2118920fed0b5949f821940cf7416.zip
cpython-e7a15bb808f2118920fed0b5949f821940cf7416.tar.gz
cpython-e7a15bb808f2118920fed0b5949f821940cf7416.tar.bz2
Merged revisions 60234-60244 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r60234 | gregory.p.smith | 2008-01-24 10:38:26 +0100 (Thu, 24 Jan 2008) | 4 lines Fix issue1789: The tutorial contained a misuse of the struct module. (also remove an unneeded import struct from test_largefile) ........ r60237 | vinay.sajip | 2008-01-24 13:37:08 +0100 (Thu, 24 Jan 2008) | 1 line Added optional delay argument to FileHandler and subclasses. ........ r60238 | vinay.sajip | 2008-01-24 13:37:33 +0100 (Thu, 24 Jan 2008) | 1 line Added optional delay argument to FileHandler and subclasses. ........ r60239 | vinay.sajip | 2008-01-24 13:38:30 +0100 (Thu, 24 Jan 2008) | 1 line Added documentation for optional delay argument to FileHandler and subclasses. ........ r60240 | vinay.sajip | 2008-01-24 13:43:33 +0100 (Thu, 24 Jan 2008) | 1 line Updated for optional delay argument to FileHandler and subclasses. ........ r60243 | guido.van.rossum | 2008-01-24 16:53:22 +0100 (Thu, 24 Jan 2008) | 2 lines Fi debug turd -- a call accidentally left out. ........
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/__init__.py25
-rw-r--r--Lib/logging/handlers.py25
2 files changed, 34 insertions, 16 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 68fd10c..762ea43 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -38,8 +38,8 @@ except ImportError:
__author__ = "Vinay Sajip <vinay_sajip@red-dove.com>"
__status__ = "production"
-__version__ = "0.5.0.4"
-__date__ = "18 January 2008"
+__version__ = "0.5.0.5"
+__date__ = "24 January 2008"
#---------------------------------------------------------------------------
# Miscellaneous module data
@@ -760,7 +760,7 @@ class FileHandler(StreamHandler):
"""
A handler class which writes formatted logging records to disk files.
"""
- def __init__(self, filename, mode='a', encoding=None):
+ def __init__(self, filename, mode='a', encoding=None, delay=0):
"""
Open the specified file and use it as the stream for logging.
"""
@@ -771,8 +771,11 @@ class FileHandler(StreamHandler):
self.baseFilename = os.path.abspath(filename)
self.mode = mode
self.encoding = encoding
- stream = self._open()
- StreamHandler.__init__(self, stream)
+ if delay:
+ self.stream = None
+ else:
+ stream = self._open()
+ StreamHandler.__init__(self, stream)
def close(self):
"""
@@ -795,6 +798,18 @@ class FileHandler(StreamHandler):
stream = codecs.open(self.baseFilename, self.mode, self.encoding)
return stream
+ def emit(self, record):
+ """
+ Emit a record.
+
+ If the stream was not opened because 'delay' was specified in the
+ constructor, open it before calling the superclass's emit.
+ """
+ if self.stream is None:
+ stream = self._open()
+ StreamHandler.__init__(self, stream)
+ StreamHandler.emit(self, record)
+
#---------------------------------------------------------------------------
# Manager classes and functions
#---------------------------------------------------------------------------
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 08bebbd..850e3bd 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -51,13 +51,13 @@ class BaseRotatingHandler(logging.FileHandler):
Not meant to be instantiated directly. Instead, use RotatingFileHandler
or TimedRotatingFileHandler.
"""
- def __init__(self, filename, mode, encoding=None):
+ def __init__(self, filename, mode, encoding=None, delay=0):
"""
Use the specified filename for streamed logging
"""
if codecs is None:
encoding = None
- logging.FileHandler.__init__(self, filename, mode, encoding)
+ logging.FileHandler.__init__(self, filename, mode, encoding, delay)
self.mode = mode
self.encoding = encoding
@@ -82,7 +82,7 @@ class RotatingFileHandler(BaseRotatingHandler):
Handler for logging to a set of files, which switches from one file
to the next when the current file reaches a certain size.
"""
- def __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None):
+ def __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=0):
"""
Open the specified file and use it as the stream for logging.
@@ -105,7 +105,7 @@ class RotatingFileHandler(BaseRotatingHandler):
"""
if maxBytes > 0:
mode = 'a' # doesn't make sense otherwise!
- BaseRotatingHandler.__init__(self, filename, mode, encoding)
+ BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
self.maxBytes = maxBytes
self.backupCount = backupCount
@@ -154,8 +154,8 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
If backupCount is > 0, when rollover is done, no more than backupCount
files are kept - the oldest ones are deleted.
"""
- def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None):
- BaseRotatingHandler.__init__(self, filename, 'a', encoding)
+ def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None, delay=0):
+ BaseRotatingHandler.__init__(self, filename, 'a', encoding, delay)
self.when = when.upper()
self.backupCount = backupCount
# Calculate the real rollover interval, which is just the number of
@@ -300,10 +300,13 @@ class WatchedFileHandler(logging.FileHandler):
This handler is based on a suggestion and patch by Chad J.
Schroeder.
"""
- def __init__(self, filename, mode='a', encoding=None):
- logging.FileHandler.__init__(self, filename, mode, encoding)
- stat = os.stat(self.baseFilename)
- self.dev, self.ino = stat[ST_DEV], stat[ST_INO]
+ def __init__(self, filename, mode='a', encoding=None, delay=0):
+ logging.FileHandler.__init__(self, filename, mode, encoding, delay)
+ if not os.path.exists(self.baseFilename):
+ self.dev, self.ino = -1, -1
+ else:
+ stat = os.stat(self.baseFilename)
+ self.dev, self.ino = stat[ST_DEV], stat[ST_INO]
def emit(self, record):
"""
@@ -319,7 +322,7 @@ class WatchedFileHandler(logging.FileHandler):
else:
stat = os.stat(self.baseFilename)
changed = (stat[ST_DEV] != self.dev) or (stat[ST_INO] != self.ino)
- if changed:
+ if changed and self.stream is not None:
self.stream.flush()
self.stream.close()
self.stream = self._open()