Skip to content

Commit

Permalink
CLI: Log normal output to stdout #54
Browse files Browse the repository at this point in the history
  • Loading branch information
benkehoe authored and Ben Kehoe committed Mar 30, 2022
1 parent 7b72be6 commit aabf773
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cli/src/aws_sso_util/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit aabf773

Please sign in to comment.