]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38781: Clear buffer in MemoryHandler flush (GH-17132)
authorDaniel Andersson <daniel.4ndersson@gmail.com>
Wed, 13 Nov 2019 09:03:45 +0000 (10:03 +0100)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Wed, 13 Nov 2019 09:03:45 +0000 (09:03 +0000)
This makes it easier to use a custom buffer when subclassing
MemoryHandler (by avoiding the explicity empty list literal
assignment in the flush method). For example, collection.deque
can now be used without any modifications to MemoryHandler.flush.

The same applies to BufferingHandler.

Lib/logging/handlers.py

index c1aec9880d72abf9e15d586fecceb27531155ee8..ea14541e1e500aa8f4369ec9bfa18a62522da97d 100644 (file)
@@ -1254,7 +1254,7 @@ class BufferingHandler(logging.Handler):
         """
         self.acquire()
         try:
-            self.buffer = []
+            self.buffer.clear()
         finally:
             self.release()
 
@@ -1321,7 +1321,7 @@ class MemoryHandler(BufferingHandler):
             if self.target:
                 for record in self.buffer:
                     self.target.handle(record)
-                self.buffer = []
+                self.buffer.clear()
         finally:
             self.release()