Skip to content

Commit

Permalink
[logger] Fix ref before assignment bug if collor code is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
SanWieb committed Sep 21, 2024
1 parent 00b6278 commit 9da6a9e
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions analyzer/shared/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"


Expand Down

0 comments on commit 9da6a9e

Please sign in to comment.