[BACKEND] Reset debug log on every subscription

This commit is contained in:
Jesse Bannon 2023-03-02 16:39:03 -08:00
parent 5d40d02eb3
commit 0fdecc762f
2 changed files with 19 additions and 5 deletions

View file

@ -40,7 +40,7 @@ def _download_subscriptions_from_yaml_files(
subscriptions: List[Subscription] = [] subscriptions: List[Subscription] = []
output: List[Tuple[Subscription, FileHandlerTransactionLog]] = [] output: List[Tuple[Subscription, FileHandlerTransactionLog]] = []
# Load all of the subscriptions first to perform all validation before downloading # Load all the subscriptions first to perform all validation before downloading
for path in subscription_paths: for path in subscription_paths:
subscriptions += Subscription.from_file_path(config=config, subscription_path=path) subscriptions += Subscription.from_file_path(config=config, subscription_path=path)
@ -55,6 +55,7 @@ def _download_subscriptions_from_yaml_files(
output.append((subscription, transaction_log)) output.append((subscription, transaction_log))
gc.collect() # Garbage collect after each subscription download gc.collect() # Garbage collect after each subscription download
Logger.cleanup() # Cleanup logger after each successful subscription download
return output return output

View file

@ -94,9 +94,22 @@ class TestLogger:
assert lines == ["[ytdl-sub:name_test] info test\n", "[ytdl-sub:name_test] debug test\n"] assert lines == ["[ytdl-sub:name_test] info test\n", "[ytdl-sub:name_test] debug test\n"]
# Ensure the file cleans up too Logger.cleanup(delete_debug_file=True)
for handler in logger.handlers: assert not os.path.isfile(Logger._DEBUG_LOGGER_FILE.name)
handler.close()
def test_logger_can_be_cleaned_during_execution(self):
Logger._LOGGER_LEVEL = LoggerLevels.INFO
logger = Logger.get(name="name_test")
for _ in range(2):
logger.info("info test")
logger.debug("debug test")
with open(Logger._DEBUG_LOGGER_FILE.name, "r", encoding="utf-8") as log_file:
lines = log_file.readlines()
assert lines == ["[ytdl-sub:name_test] info test\n", "[ytdl-sub:name_test] debug test\n"]
Logger.cleanup(delete_debug_file=True) Logger.cleanup(delete_debug_file=True)
assert not os.path.isfile(Logger._DEBUG_LOGGER_FILE.name) assert not os.path.isfile(Logger._DEBUG_LOGGER_FILE.name)