summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-02-23 20:20:08 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-02-23 20:20:08 (GMT)
commit03d23687480c77130e7fc28f323ec75413e6f060 (patch)
tree41b2050b9f2d2f865991ec6117e411f92768b060 /Lib
parentd8f4118f9b554a0c2110fb9d3f33fa5fa0a6c488 (diff)
parent16f6a29be8fe709c133f07150c1326451139faae (diff)
downloadcpython-03d23687480c77130e7fc28f323ec75413e6f060.zip
cpython-03d23687480c77130e7fc28f323ec75413e6f060.tar.gz
cpython-03d23687480c77130e7fc28f323ec75413e6f060.tar.bz2
merge heads
Diffstat (limited to 'Lib')
-rw-r--r--Lib/logging/__init__.py24
-rw-r--r--Lib/logging/handlers.py36
2 files changed, 33 insertions, 27 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index be775e8..4b23cb4 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.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,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-2010 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
"""
@@ -828,8 +828,9 @@ class StreamHandler(Handler):
"""
Flushes the stream.
"""
- if self.stream and hasattr(self.stream, "flush"):
- self.stream.flush()
+ with self.lock:
+ if self.stream and hasattr(self.stream, "flush"):
+ self.stream.flush()
def emit(self, record):
"""
@@ -900,12 +901,13 @@ 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
+ with self.lock:
+ if self.stream:
+ self.flush()
+ if hasattr(self.stream, "close"):
+ self.stream.close()
+ StreamHandler.close(self)
+ self.stream = None
def _open(self):
"""
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index f8c7164..fe5f9bf 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!
"""
@@ -563,9 +562,10 @@ class SocketHandler(logging.Handler):
"""
Closes the socket.
"""
- if self.sock:
- self.sock.close()
- self.sock = None
+ with self.lock:
+ if self.sock:
+ self.sock.close()
+ self.sock = None
logging.Handler.close(self)
class DatagramHandler(SocketHandler):
@@ -767,8 +767,9 @@ class SysLogHandler(logging.Handler):
"""
Closes the socket.
"""
- if self.unixsocket:
- self.socket.close()
+ with self.lock:
+ if self.unixsocket:
+ self.socket.close()
logging.Handler.close(self)
def mapPriority(self, levelName):
@@ -1096,7 +1097,8 @@ class BufferingHandler(logging.Handler):
This version just zaps the buffer to empty.
"""
- self.buffer = []
+ with self.lock:
+ self.buffer = []
def close(self):
"""
@@ -1144,15 +1146,17 @@ class MemoryHandler(BufferingHandler):
records to the target, if there is one. Override if you want
different behaviour.
"""
- if self.target:
- for record in self.buffer:
- self.target.handle(record)
- self.buffer = []
+ with self.lock:
+ if self.target:
+ for record in self.buffer:
+ self.target.handle(record)
+ self.buffer = []
def close(self):
"""
Flush, set the target to None and lose the buffer.
"""
self.flush()
- self.target = None
- BufferingHandler.close(self)
+ with self.lock:
+ self.target = None
+ BufferingHandler.close(self)