Skip to content

Commit

Permalink
Redirect error logs to stderr stream
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Oct 12, 2023
1 parent 1fcb04f commit cb6024e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/codemodder/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import sys

logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.INFO)
logger = logging.getLogger("codemodder")


Expand All @@ -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],
)

0 comments on commit cb6024e

Please sign in to comment.