From 9da6a9e76226d2438506086c55e8f305e40981a3 Mon Sep 17 00:00:00 2001 From: Sander Wiebing <45387038+SanWieb@users.noreply.github.com> Date: Sat, 21 Sep 2024 13:07:09 +0200 Subject: [PATCH] [logger] Fix ref before assignment bug if collor code is 0 --- analyzer/shared/logger.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/analyzer/shared/logger.py b/analyzer/shared/logger.py index 1f309eb..a220249 100644 --- a/analyzer/shared/logger.py +++ b/analyzer/shared/logger.py @@ -14,19 +14,16 @@ def format(self, record): name: str = record.name level: str = record.levelname message: str = record.getMessage() - name_len: int = len(name) - lvl_len: int = len(level) - - if sys.stdout.isatty(): - # Choose a different color for each logger. - c: int = zlib.adler32(name.encode()) % 7 - c = (c + zlib.adler32(level.encode())) % 7 - if c != 0: # Do not color black or white, allow 'uncolored' - col = Color(c + Color.black.value) + + # Choose a different color for each logger. + c: int = zlib.adler32(name.encode()) % 7 + c = (c + zlib.adler32(level.encode())) % 7 + + if c != 0 and sys.stdout.isatty(): + col = Color(c + Color.black.value) return color(col, False) + f"[{name}] {message}{ENDC}" else: - return f"[{name}] {message}"