Skip to content

Commit

Permalink
--version does not log log level (conda-incubator#47)
Browse files Browse the repository at this point in the history
Also do not log the log level if
verbosity is zero.
  • Loading branch information
analog-cbarber committed Jul 15, 2021
1 parent a8601d5 commit 202bed4
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions conda_mirror/conda_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def _str_or_false(x: str) -> Union[str, bool]:
x = False
return x


def _make_arg_parser():
"""
Localize the ArgumentParser logic
Expand Down Expand Up @@ -276,9 +277,7 @@ def _make_arg_parser():
)
ap.add_argument(
"--platform",
help=(
f"The OS platform(s) to mirror. one of: {', '.join(DEFAULT_PLATFORMS)}"
),
help=(f"The OS platform(s) to mirror. one of: {', '.join(DEFAULT_PLATFORMS)}"),
)
ap.add_argument(
"-D",
Expand Down Expand Up @@ -388,12 +387,12 @@ def _make_arg_parser():
return ap


def _init_logger(verbosity):
def _init_logger(verbosity: int) -> None:
# set up the logger
global logger
logger = logging.getLogger("conda_mirror")
logmap = {0: logging.ERROR, 1: logging.WARNING, 2: logging.INFO, 3: logging.DEBUG}
loglevel = logmap.get(verbosity, "3")
loglevel = logmap.get(min(int(verbosity), 3))

# clear all handlers
for handler in logger.handlers:
Expand All @@ -407,9 +406,8 @@ def _init_logger(verbosity):

logger.addHandler(stream_handler)

print(
"Log level set to %s" % logging.getLevelName(logmap[verbosity]), file=sys.stdout
)
if verbosity > 0:
print("Log level set to %s" % logging.getLevelName(loglevel))


def _parse_and_format_args():
Expand All @@ -421,15 +419,17 @@ def _parse_and_format_args():
# parse arguments without setting defaults
given_args, _ = parser._parse_known_args(sys.argv[1:], argparse.Namespace())

_init_logger(args.verbose)
logger.debug("sys.argv: %s", sys.argv)

if args.version:
from . import __version__

print(__version__)
sys.exit(1)

verbosity = int(args.verbose)

_init_logger(verbosity)
logger.debug("sys.argv: %s", sys.argv)

config_dict = {}
if args.config:
logger.info("Loading config from %s", args.config)
Expand Down

0 comments on commit 202bed4

Please sign in to comment.