Skip to content

Commit

Permalink
Merge pull request #54 from konflux-ci/less-verbose-stderr
Browse files Browse the repository at this point in the history
Only print errors to stderr
  • Loading branch information
lubomir authored Dec 2, 2024
2 parents 4973d9e + 8561765 commit 51d7d9a
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 @@ -364,6 +364,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 @@ -391,7 +411,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 51d7d9a

Please sign in to comment.