[BACKEND] Reset debug log on every subscription (#497)
This commit is contained in:
parent
628c0f1f43
commit
896a9e2073
3 changed files with 22 additions and 6 deletions
|
|
@ -40,7 +40,7 @@ def _download_subscriptions_from_yaml_files(
|
|||
subscriptions: List[Subscription] = []
|
||||
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:
|
||||
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))
|
||||
gc.collect() # Garbage collect after each subscription download
|
||||
Logger.cleanup() # Cleanup logger after each successful subscription download
|
||||
|
||||
return output
|
||||
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ class Logger:
|
|||
@classmethod
|
||||
def cleanup(cls, delete_debug_file: bool = True):
|
||||
"""
|
||||
Cleans up any log files left behind.
|
||||
Cleans up any log files left behind
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
|
|
|||
|
|
@ -94,13 +94,28 @@ class TestLogger:
|
|||
|
||||
assert lines == ["[ytdl-sub:name_test] info test\n", "[ytdl-sub:name_test] debug test\n"]
|
||||
|
||||
# Ensure the file cleans up too
|
||||
for handler in logger.handlers:
|
||||
handler.close()
|
||||
|
||||
Logger.cleanup(delete_debug_file=True)
|
||||
assert not os.path.isfile(Logger._DEBUG_LOGGER_FILE.name)
|
||||
|
||||
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)
|
||||
assert not os.path.isfile(Logger._DEBUG_LOGGER_FILE.name)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"log_level, expected_stdout",
|
||||
[
|
||||
|
|
|
|||
Loading…
Reference in a new issue