From 470f85b009962d10210a13f9751a8a58bb77d809 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 16 Jan 2019 12:03:56 +0000 Subject: Pushing logging on to another thread was a ridiculous idea. it means CRITICAL logs are in a race condition to write to file before the main thread exits. --- src/Logging.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'src/Logging.py') diff --git a/src/Logging.py b/src/Logging.py index 60c008a6..8de57d83 100644 --- a/src/Logging.py +++ b/src/Logging.py @@ -1,4 +1,4 @@ -import logging, logging.handlers, os, queue, sys, threading, time, typing +import logging, logging.handlers, os, queue, sys, time, typing LEVELS = { "trace": logging.DEBUG-1, @@ -54,16 +54,6 @@ class Log(object): warn_handler.setFormatter(formatter) self.logger.addHandler(warn_handler) - self._queue = queue.Queue() # type: queue.Queue[typing.Tuple[str, typing.List, int, typing.Dict]] - self._thread = threading.Thread(target=self._loop) - self._thread.daemon = True - self._thread.start() - - def _loop(self): - while True: - message, params, level, kwargs = self._queue.get(block=True) - self.logger.log(level, message, *params, **kwargs) - def trace(self, message: str, params: typing.List, **kwargs): self._log(message, params, LEVELS["trace"], kwargs) def debug(self, message: str, params: typing.List, **kwargs): @@ -77,8 +67,4 @@ class Log(object): def critical(self, message: str, params: typing.List, **kwargs): self._log(message, params, logging.CRITICAL, kwargs) def _log(self, message: str, params: typing.List, level: int, kwargs: dict): - if kwargs.get("exc_info") == True: - # because we're doing the actual logging on another thread, - # we need to catch actual exception information here. - kwargs["exc_info"] = sys.exc_info() - self._queue.put((message, params, level, kwargs)) + self.logger.log(level, message, *params, **kwargs) -- cgit v1.3.1-10-gc9f91