From c196a38e09da396bb94c5c281148671339072b47 Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Sat, 25 Jul 2020 06:53:40 +0100 Subject: [PATCH] Add logging TODOs. logger creation & frame detection * Nothing should "from EDMarketConnector import logger" any more, so we can move this back inside __main__ section * We shouldn't rely on a magic number of frames to skip. Detect the proper frame automatically. --- EDMarketConnector.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 1fdc1a9f..6685ddd0 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -947,6 +947,7 @@ def enforce_single_instance() -> None: # Logging # Has to be here to be defined for other modules importing +# TODO: now nothing should import this, can it move back into __main__ block ? logger = logging.getLogger(appname) class EDMCContextFilter(logging.Filter): @@ -982,6 +983,11 @@ class EDMCContextFilter(logging.Filter): return framelist stack = stack_(sys._getframe(1)) + # TODO: Make this less fragile by not depending on a magic number of + # stack frames to skip. Should be able to find the last + # logger frame, where one of the critical, debug etc functions + # was called and then use the next frame before that. + # ALSO UPDATE caller_qualname() !!! start = 0 + skip if len(stack) < start + 1: return ''