Skip to content

Commit 21504fd

Browse files
committed
print location and name of debug file
improved print prefixing version bump v0.9.14
1 parent c1ad7f1 commit 21504fd

3 files changed

Lines changed: 30 additions & 22 deletions

File tree

zotify/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
__version__ = "0.9.13"
2+
__version__ = "0.9.14"
33

44
from enum import IntEnum
55
from http.server import BaseHTTPRequestHandler, HTTPServer

zotify/config.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,33 +176,37 @@ def load(cls, args) -> None:
176176
full_config_path = full_config_path.parent / (full_config_path.stem + "_DEBUG.json")
177177
with open(full_config_path, 'w' if full_config_path.exists() else 'x', encoding='utf-8') as debug_file:
178178
json.dump(cls.parse_config_jsonstr(), debug_file, indent=4)
179-
Printer.hashtaged(PrintChannel.MANDATORY, f"{full_config_path.name} saved to {full_config_path.resolve().parent}")
179+
real_debug = cls.Values[DEBUG]; cls.Values[DEBUG] = True
180+
Printer.hashtaged(PrintChannel.DEBUG, f"{full_config_path.name} saved to {full_config_path.resolve().parent}")
181+
cls.Values[DEBUG] = real_debug
180182

181183
# Override config from commandline arguments
182184
for key in CONFIG_VALUES:
183185
if key.lower() in vars(args) and vars(args)[key.lower()] is not None:
184186
cls.Values[key] = cls.parse_arg_value(key, vars(args)[key.lower()])
185187

188+
# Handle sub-library logging
189+
if cls.debug():
190+
logfile = Path(cls.get_root_path()/f"zotify_DEBUG_{Zotify.DATETIME_LAUNCH}.log")
191+
Printer.hashtaged(PrintChannel.DEBUG, f"{logfile.name} logging to {logfile.resolve().parent}")
192+
logging.basicConfig(level=logging.DEBUG, filemode="x", filename=logfile)
193+
cls.logger = logging.getLogger("zotify.debug")
194+
else:
195+
logging.basicConfig(level=logging.CRITICAL)
196+
# mutedLoggers = {"Librespot:Session", "Librespot:AudioKeyManager", "librespot.audio", "Librespot:CdnManager"}
197+
# for logger in mutedLoggers:
198+
# logging.getLogger(logger).disabled = True
199+
186200
# Confirm regex patterns
187201
if cls.get_regex_enabled():
188202
for mode in ["Track", "Episode", "Album"]:
189203
regex_method: Callable[[None], None | re.Pattern] = getattr(cls, f"get_regex_{mode.lower()}")
190-
if regex_method(): Printer.hashtaged(PrintChannel.MANDATORY, f'{mode} Regex Filter: r"{regex_method().pattern}"')
204+
if regex_method(): Printer.hashtaged(PrintChannel.DEBUG, f'{mode} Regex Filter: r"{regex_method().pattern}"')
191205

192206
# Check no-splash
193207
if args.no_splash:
194208
cls.Values[PRINT_SPLASH] = False
195209

196-
# Handle sub-library logging
197-
if cls.Values[DEBUG]:
198-
logfile = cls.get_root_path()/f"zotify_DEBUG_{Zotify.DATETIME_LAUNCH}.log"
199-
logging.basicConfig(level=logging.DEBUG, filemode="x", filename=logfile)
200-
cls.logger = logging.getLogger("zotify.debug")
201-
else:
202-
logging.basicConfig(level=logging.CRITICAL)
203-
# mutedLoggers = {"Librespot:Session", "Librespot:AudioKeyManager", "librespot.audio", "Librespot:CdnManager"}
204-
# for logger in mutedLoggers:
205-
# logging.getLogger(logger).disabled = True
206210

207211
@classmethod
208212
def get_default_json(cls) -> dict:

zotify/termoutput.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,29 @@ def shrink(k: str) -> str:
9494
return obj
9595

9696
@staticmethod
97-
def _print_prefixes(msg: str, category: PrintCategory, channel: PrintChannel) -> str:
97+
def _print_prefixes(msg: str, category: PrintCategory, channel: PrintChannel) -> tuple[str, PrintCategory]:
9898
if category is PrintCategory.HASHTAG:
9999
if channel in {PrintChannel.WARNING, PrintChannel.ERROR, PrintChannel.API_ERROR,
100100
PrintChannel.SKIPPING,}:
101101
msg = channel.name + ": " + msg
102102
msg = msg.replace("\n", " ###\n### ") + " ###"
103+
if channel is PrintChannel.DEBUG:
104+
msg = category.value.replace("\n", "", 1) + msg
105+
category = PrintCategory.DEBUG
103106
elif category is PrintCategory.JSON:
104107
msg = "#" * (Printer._term_cols()-1) + "\n" + msg + "\n" + "#" * Printer._term_cols()
105108

106109
global LAST_PRINT
107110
if LAST_PRINT is PrintCategory.DEBUG and category is PrintCategory.DEBUG:
108-
return msg
109-
elif LAST_PRINT in {PrintCategory.LOADER, PrintCategory.LOADER_CYCLE}:
110-
if category is PrintCategory.LOADER:
111-
return "\n" + PrintCategory.LOADER_CYCLE.value + msg
112-
elif "LOADER" not in category.name:
113-
return category.value.replace("\n", "", 1) + msg
111+
pass
112+
elif LAST_PRINT in {PrintCategory.LOADER, PrintCategory.LOADER_CYCLE} and category is PrintCategory.LOADER:
113+
msg = "\n" + PrintCategory.LOADER_CYCLE.value + msg
114+
elif LAST_PRINT in {PrintCategory.LOADER, PrintCategory.LOADER_CYCLE} and "LOADER" not in category.name:
115+
msg = category.value.replace("\n", "", 1) + msg
116+
else:
117+
msg = category.value + msg
114118

115-
return category.value + msg
119+
return msg, category
116120

117121
@staticmethod
118122
def _toggle_active_loader(skip_toggle: bool = False):
@@ -129,7 +133,7 @@ def new_print(channel: PrintChannel, msg: str, category: PrintCategory = PrintCa
129133
if channel != PrintChannel.MANDATORY:
130134
from zotify.config import Zotify
131135
if channel == PrintChannel.MANDATORY or Zotify.CONFIG.get(channel.value):
132-
msg = Printer._print_prefixes(msg, category, channel)
136+
msg, category = Printer._print_prefixes(msg, category, channel)
133137
if channel == PrintChannel.DEBUG and Zotify.CONFIG.logger:
134138
Zotify.CONFIG.logger.debug(msg.strip().replace("DEBUG", "\n") + "\n")
135139
Printer._toggle_active_loader(skip_toggle)

0 commit comments

Comments
 (0)