|
1 | | -# Copyright 2001-2010 by Vinay Sajip. All Rights Reserved. |
| 1 | +# Copyright 2001-2012 by Vinay Sajip. All Rights Reserved. |
2 | 2 | # |
3 | 3 | # Permission to use, copy, modify, and distribute this software and its |
4 | 4 | # documentation for any purpose and without fee is hereby granted, |
|
16 | 16 |
|
17 | 17 | """ |
18 | 18 | Additional handlers for the logging package for Python. The core package is |
19 | | -based on PEP 282 and comments thereto in comp.lang.python, and influenced by |
20 | | -Apache's log4j system. |
| 19 | +based on PEP 282 and comments thereto in comp.lang.python. |
21 | 20 |
|
22 | | -Copyright (C) 2001-2010 Vinay Sajip. All Rights Reserved. |
| 21 | +Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved. |
23 | 22 |
|
24 | 23 | To use, simply 'import logging.handlers' and log away! |
25 | 24 | """ |
@@ -554,10 +553,11 @@ def close(self): |
554 | 553 | """ |
555 | 554 | Closes the socket. |
556 | 555 | """ |
557 | | - if self.sock: |
558 | | - self.sock.close() |
559 | | - self.sock = None |
560 | | - logging.Handler.close(self) |
| 556 | + with self.lock: |
| 557 | + if self.sock: |
| 558 | + self.sock.close() |
| 559 | + self.sock = None |
| 560 | + logging.Handler.close(self) |
561 | 561 |
|
562 | 562 | class DatagramHandler(SocketHandler): |
563 | 563 | """ |
@@ -752,9 +752,10 @@ def close (self): |
752 | 752 | """ |
753 | 753 | Closes the socket. |
754 | 754 | """ |
755 | | - if self.unixsocket: |
756 | | - self.socket.close() |
757 | | - logging.Handler.close(self) |
| 755 | + with self.lock: |
| 756 | + if self.unixsocket: |
| 757 | + self.socket.close() |
| 758 | + logging.Handler.close(self) |
758 | 759 |
|
759 | 760 | def mapPriority(self, levelName): |
760 | 761 | """ |
@@ -1095,7 +1096,8 @@ def flush(self): |
1095 | 1096 |
|
1096 | 1097 | This version just zaps the buffer to empty. |
1097 | 1098 | """ |
1098 | | - self.buffer = [] |
| 1099 | + with self.lock: |
| 1100 | + self.buffer = [] |
1099 | 1101 |
|
1100 | 1102 | def close(self): |
1101 | 1103 | """ |
@@ -1145,18 +1147,20 @@ def flush(self): |
1145 | 1147 |
|
1146 | 1148 | The record buffer is also cleared by this operation. |
1147 | 1149 | """ |
1148 | | - if self.target: |
1149 | | - for record in self.buffer: |
1150 | | - self.target.handle(record) |
1151 | | - self.buffer = [] |
| 1150 | + with self.lock: |
| 1151 | + if self.target: |
| 1152 | + for record in self.buffer: |
| 1153 | + self.target.handle(record) |
| 1154 | + self.buffer = [] |
1152 | 1155 |
|
1153 | 1156 | def close(self): |
1154 | 1157 | """ |
1155 | 1158 | Flush, set the target to None and lose the buffer. |
1156 | 1159 | """ |
1157 | 1160 | self.flush() |
1158 | | - self.target = None |
1159 | | - BufferingHandler.close(self) |
| 1161 | + with self.lock: |
| 1162 | + self.target = None |
| 1163 | + BufferingHandler.close(self) |
1160 | 1164 |
|
1161 | 1165 |
|
1162 | 1166 | class QueueHandler(logging.Handler): |
|
0 commit comments