summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-02-23 23:30:04 (GMT)
committerBrett Cannon <brett@python.org>2012-02-23 23:30:04 (GMT)
commitdcb30cf959902fdc3da027c13a99e091d116c273 (patch)
treef038152eff31dc79bb3a11d2c77871f9add9a27a /Lib
parentf500778f652f6beb368f10c0fd312c3034dfce5e (diff)
parent0a786221d9458aedba420a8a78d7768a7e349031 (diff)
downloadcpython-dcb30cf959902fdc3da027c13a99e091d116c273.zip
cpython-dcb30cf959902fdc3da027c13a99e091d116c273.tar.gz
cpython-dcb30cf959902fdc3da027c13a99e091d116c273.tar.bz2
merge
Diffstat (limited to 'Lib')
-rw-r--r--Lib/logging/__init__.py28
-rw-r--r--Lib/logging/handlers.py53
2 files changed, 54 insertions, 27 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 8fe5bd9..e79018f 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -16,9 +16,9 @@
"""
Logging package for Python. Based on PEP 282 and comments thereto in
-comp.lang.python, and influenced by Apache's log4j system.
+comp.lang.python.
-Copyright (C) 2001-2011 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
"""
@@ -914,8 +914,12 @@ class StreamHandler(Handler):
"""
Flushes the stream.
"""
- if self.stream and hasattr(self.stream, "flush"):
- self.stream.flush()
+ self.acquire()
+ try:
+ if self.stream and hasattr(self.stream, "flush"):
+ self.stream.flush()
+ finally:
+ self.release()
def emit(self, record):
"""
@@ -964,12 +968,16 @@ class FileHandler(StreamHandler):
"""
Closes the stream.
"""
- if self.stream:
- self.flush()
- if hasattr(self.stream, "close"):
- self.stream.close()
- StreamHandler.close(self)
- self.stream = None
+ self.acquire()
+ try:
+ if self.stream:
+ self.flush()
+ if hasattr(self.stream, "close"):
+ self.stream.close()
+ StreamHandler.close(self)
+ self.stream = None
+ finally:
+ self.release()
def _open(self):
"""
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 822b4ef..ee0096a 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -1,4 +1,4 @@
-# Copyright 2001-2010 by Vinay Sajip. All Rights Reserved.
+# Copyright 2001-2012 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,
@@ -16,10 +16,9 @@
"""
Additional handlers for the logging package for Python. The core package is
-based on PEP 282 and comments thereto in comp.lang.python, and influenced by
-Apache's log4j system.
+based on PEP 282 and comments thereto in comp.lang.python.
-Copyright (C) 2001-2010 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging.handlers' and log away!
"""
@@ -594,10 +593,14 @@ class SocketHandler(logging.Handler):
"""
Closes the socket.
"""
- if self.sock:
- self.sock.close()
- self.sock = None
- logging.Handler.close(self)
+ self.acquire()
+ try:
+ if self.sock:
+ self.sock.close()
+ self.sock = None
+ logging.Handler.close(self)
+ finally:
+ self.release()
class DatagramHandler(SocketHandler):
"""
@@ -792,8 +795,12 @@ class SysLogHandler(logging.Handler):
"""
Closes the socket.
"""
- self.socket.close()
- logging.Handler.close(self)
+ self.acquire()
+ try:
+ self.socket.close()
+ logging.Handler.close(self)
+ finally:
+ self.release()
def mapPriority(self, levelName):
"""
@@ -1137,7 +1144,11 @@ class BufferingHandler(logging.Handler):
This version just zaps the buffer to empty.
"""
- self.buffer = []
+ self.acquire()
+ try:
+ self.buffer = []
+ finally:
+ self.release()
def close(self):
"""
@@ -1187,18 +1198,26 @@ class MemoryHandler(BufferingHandler):
The record buffer is also cleared by this operation.
"""
- if self.target:
- for record in self.buffer:
- self.target.handle(record)
- self.buffer = []
+ self.acquire()
+ try:
+ if self.target:
+ for record in self.buffer:
+ self.target.handle(record)
+ self.buffer = []
+ finally:
+ self.release()
def close(self):
"""
Flush, set the target to None and lose the buffer.
"""
self.flush()
- self.target = None
- BufferingHandler.close(self)
+ self.acquire()
+ try:
+ self.target = None
+ BufferingHandler.close(self)
+ finally:
+ self.release()
class QueueHandler(logging.Handler):