Skip to content

Commit

Permalink
tweak logging format
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiko2k committed Dec 3, 2024
1 parent 3399458 commit 04750af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/tauon/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,23 @@
class CustomLoggingFormatter(logging.Formatter):
"""Nicely format logging.loglevel logs"""

grey = "\x1b[38;20m"
grey_bold = "\x1b[38;1m"
grey = "\x1b[0;20m"
grey_bold = "\x1b[0;1m"
yellow = "\x1b[33;20m"
yellow_bold = "\x1b[33;1m"
red = "\x1b[31;20m"
bold_red = "\x1b[31;1m"
purple = "\x1b[0;35m"
reset = "\x1b[0m"
format = "%(asctime)s [%(levelname)s] [%(module)s] %(message)s"
format_verbose = "%(asctime)s [%(levelname)s] [%(module)s] %(message)s (%(filename)s:%(lineno)d)"

# TODO(Martin): Add some way in which devel mode uses everything verbose
FORMATS = {
logging.DEBUG: grey_bold + format_verbose + reset,
logging.INFO: yellow + format + reset,
logging.WARNING: yellow_bold + format + reset,
logging.ERROR: red + format + reset,
logging.INFO: grey + format + reset,
logging.WARNING: purple + format_verbose + reset,
logging.ERROR: red + format_verbose + reset,
logging.CRITICAL: bold_red + format_verbose + reset,
}

Expand All @@ -109,7 +110,7 @@ def format(self, record: dict) -> str:
],
)
# INFO+ to std_err
logging.getLogger().handlers[0].setLevel(logging.INFO)
logging.getLogger().handlers[0].setLevel(logging.DEBUG)
logging.getLogger().handlers[0].setFormatter(CustomLoggingFormatter())

if sys.platform != "win32":
Expand Down
7 changes: 4 additions & 3 deletions src/tauon/t_modules/t_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11988,7 +11988,7 @@ def render(self, track: TrackClass, location, size=None, force_offset=None) -> b
self.lock.release()
except RuntimeError as e:
if str(e) == "release unlocked lock":
logging.error("RuntimeError: Attempted to release already unlocked lock")
logging.debug("RuntimeError: Attempted to release already unlocked lock")
else:
logging.exception("Unknown RuntimeError trying to release lock: {e}")
except Exception:
Expand Down Expand Up @@ -12429,7 +12429,8 @@ def get_embed(self, track: TrackClass):
try:
tag = mutagen.id3.ID3(filepath)
frame = tag.getall("APIC")
pic = frame[0].data
if frame:
pic = frame[0].data
except Exception:
logging.exception("Failed to get tags")

Expand Down Expand Up @@ -44139,7 +44140,7 @@ def drop_file(target):
tm.player_lock.release()
except RuntimeError as e:
if str(e) == "release unlocked lock":
logging.error("RuntimeError: Attempted to release already unlocked player_lock")
logging.debug("RuntimeError: Attempted to release already unlocked player_lock")
else:
logging.exception("Unknown RuntimeError trying to release player_lock: {e}")
except Exception:
Expand Down

0 comments on commit 04750af

Please sign in to comment.