From cb6024e2ecc0c5753344f6b71362713a68b19ca7 Mon Sep 17 00:00:00 2001 From: Daniel D'Avella Date: Tue, 10 Oct 2023 16:43:39 -0400 Subject: [PATCH] Redirect error logs to stderr stream --- src/codemodder/logging.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/codemodder/logging.py b/src/codemodder/logging.py index 986cf4dd..a8e9feaa 100644 --- a/src/codemodder/logging.py +++ b/src/codemodder/logging.py @@ -2,7 +2,6 @@ import logging import sys -logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.INFO) logger = logging.getLogger("codemodder") @@ -19,5 +18,18 @@ def configure_logger(verbose: bool): """ Configure the logger based on the verbosity level. """ - # TODO: eventually process human/json here - logger.setLevel(logging.DEBUG if verbose else logging.INFO) + log_level = logging.DEBUG if verbose else logging.INFO + + # TODO: this should all be conditional on the output format + stdout_handler = logging.StreamHandler(sys.stdout) + stdout_handler.setLevel(log_level) + stdout_handler.addFilter(lambda record: record.levelno <= logging.WARNING) + + stderr_handler = logging.StreamHandler(sys.stderr) + stderr_handler.setLevel(logging.ERROR) + + logging.basicConfig( + format="%(message)s", + level=log_level, + handlers=[stdout_handler, stderr_handler], + )