Skip to content

Commit

Permalink
Only print errors to stderr
Browse files Browse the repository at this point in the history
Every other message goes to stdout.

Fixes: #53
  • Loading branch information
lubomir committed Sep 17, 2024
1 parent a44afe3 commit 8561765
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion rpm_lockfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,26 @@ def _get_containerfile_filters(context):
return {}


def logging_setup(debug=False):

class ExcludeErrorsFilter(logging.Filter):
def filter(self, record):
"""Only lets through log messages with log level below ERROR."""
return record.levelno < logging.ERROR

console_stdout = logging.StreamHandler(stream=sys.stdout)
console_stdout.addFilter(ExcludeErrorsFilter())
console_stdout.setLevel(logging.DEBUG if debug else logging.INFO)

console_stderr = logging.StreamHandler(stream=sys.stderr)
console_stderr.setLevel(logging.ERROR)

logging.basicConfig(
level=logging.DEBUG if debug else logging.INFO,
handlers=[console_stdout, console_stderr],
)


def main():
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group()
Expand Down Expand Up @@ -361,7 +381,7 @@ def main():
)
args = parser.parse_args()

logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)
logging_setup(args.debug)

config_dir = os.path.dirname(os.path.realpath(args.infile))
with open(args.infile) as f:
Expand Down

0 comments on commit 8561765

Please sign in to comment.