From ee86bb76483d814ee002657428abbeba543690ab Mon Sep 17 00:00:00 2001 From: Jerry Date: Wed, 2 Jun 2021 16:40:34 +0800 Subject: [PATCH] NullHandler is causing problem --- src/pacroller/main.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pacroller/main.py b/src/pacroller/main.py index 3857cdf..8a5390f 100644 --- a/src/pacroller/main.py +++ b/src/pacroller/main.py @@ -131,7 +131,7 @@ def do_system_upgrade(debug=False, interactive=False) -> checkReport: else: raise MaxRetryReached(f'sync failed {NETWORK_RETRY} times') - stdout_handler = logging.NullHandler + stdout_handler = None if SAVE_STDOUT: try: LOG_DIR.mkdir(parents=True, exist_ok=True) @@ -142,8 +142,9 @@ def do_system_upgrade(debug=False, interactive=False) -> checkReport: stdout_handler.setLevel(logging.DEBUG) except Exception: logging.exception(f"unable to save stdout to {LOG_DIR}") - stdout_handler = logging.NullHandler - logger.addHandler(stdout_handler) + stdout_handler = None + if stdout_handler: + logger.addHandler(stdout_handler) for _ in range(NETWORK_RETRY): try: @@ -160,7 +161,8 @@ def do_system_upgrade(debug=False, interactive=False) -> checkReport: else: raise MaxRetryReached(f'upgrade failed {NETWORK_RETRY} times') - logger.removeHandler(stdout_handler) + if stdout_handler: + logger.removeHandler(stdout_handler) with open(PACMAN_LOG, 'r') as pacman_log: pacman_log.seek(log_anchor)