From 3d211e4c0ba20b70222541bc60789c24ef0f5bf4 Mon Sep 17 00:00:00 2001 From: Brennan Ashton Date: Wed, 28 Jun 2017 23:02:05 -0700 Subject: [PATCH] Flush logger buffer prior to closing handler When an application terminates any outstanding logs in the log handler buffer will be lost. Make sure that the log buffer is flushed prior to being closed. --- logdna/logdna.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/logdna/logdna.py b/logdna/logdna.py index 1644a2c..47b4b19 100644 --- a/logdna/logdna.py +++ b/logdna/logdna.py @@ -90,4 +90,12 @@ def emit(self, record): self.bufferLog(message) def close(self): - logging.Handler.close(self) + """ + Close the log handler. + + Make sure that the log handler has attempted to flush the log buffer before closing. + """ + try: + self.flush() + finally: + logging.Handler.close(self)