From aabf773201479af4c7d0e5c07a6e896bc276b88c Mon Sep 17 00:00:00 2001 From: Ben Kehoe Date: Fri, 25 Mar 2022 07:05:48 -0600 Subject: [PATCH] CLI: Log normal output to stdout #54 --- cli/src/aws_sso_util/utils.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/cli/src/aws_sso_util/utils.py b/cli/src/aws_sso_util/utils.py index c0e56ba..a67a676 100644 --- a/cli/src/aws_sso_util/utils.py +++ b/cli/src/aws_sso_util/utils.py @@ -13,9 +13,14 @@ import logging import logging.handlers +import sys from aws_sso_lib.config import find_instances, SSOInstance +class StdoutFilter(logging.Filter): + def filter(self, rec): + return rec.levelno < logging.WARNING + def configure_logging(logger, verbose, **config_args): if verbose in [False, None]: verbose = 0 @@ -29,9 +34,18 @@ def configure_logging(logger, verbose, **config_args): root_logger = logging.getLogger() if verbose == 0: - handler = logging.StreamHandler() - handler.setFormatter(logging.Formatter("%(message)s")) - logger.addHandler(handler) + stdout_handler = logging.StreamHandler(stream=sys.stdout) + stdout_handler.setFormatter(logging.Formatter("%(message)s")) + stdout_handler.setLevel(logging.DEBUG) + stdout_handler.addFilter(StdoutFilter()) + + stderr_handler = logging.StreamHandler(stream=sys.stderr) + stderr_handler.setFormatter(logging.Formatter("%(message)s")) + stderr_handler.setLevel(logging.WARNING) + + logger.addHandler(stdout_handler) + logger.addHandler(stderr_handler) + logger.propagate = False logger.setLevel(logging.INFO) elif verbose == 1: