Commit 0abf61db authored by Vinay Sajip's avatar Vinay Sajip

logging: Added locking in flush() and close() handler methods. Thanks to Fayaz...

logging: Added locking in flush() and close() handler methods. Thanks to Fayaz Yusuf Khan for the suggestion.
parent ba528f57
# 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-2011 Vinay Sajip. All Rights Reserved.
Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
"""
......@@ -917,6 +917,7 @@ class StreamHandler(Handler):
"""
Flushes the stream.
"""
with self.lock:
if self.stream and hasattr(self.stream, "flush"):
self.stream.flush()
......@@ -969,6 +970,7 @@ class FileHandler(StreamHandler):
"""
Closes the stream.
"""
with self.lock:
if self.stream:
self.flush()
if hasattr(self.stream, "close"):
......
# 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!
"""
......@@ -554,6 +553,7 @@ class SocketHandler(logging.Handler):
"""
Closes the socket.
"""
with self.lock:
if self.sock:
self.sock.close()
self.sock = None
......@@ -752,6 +752,7 @@ class SysLogHandler(logging.Handler):
"""
Closes the socket.
"""
with self.lock:
if self.unixsocket:
self.socket.close()
logging.Handler.close(self)
......@@ -1095,6 +1096,7 @@ class BufferingHandler(logging.Handler):
This version just zaps the buffer to empty.
"""
with self.lock:
self.buffer = []
def close(self):
......@@ -1145,6 +1147,7 @@ class MemoryHandler(BufferingHandler):
The record buffer is also cleared by this operation.
"""
with self.lock:
if self.target:
for record in self.buffer:
self.target.handle(record)
......@@ -1155,6 +1158,7 @@ class MemoryHandler(BufferingHandler):
Flush, set the target to None and lose the buffer.
"""
self.flush()
with self.lock:
self.target = None
BufferingHandler.close(self)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment