From da9f23afefabcf1e35053a068baeb6409229c91c Mon Sep 17 00:00:00 2001 From: Alex Nitz Date: Mon, 20 Nov 2023 23:03:51 +0100 Subject: [PATCH] Update __init__.py (#4564) * Update __init__.py This would modify init_logging in pycbc to work with a 'count' argument. This means if you give --verbose, the logging level is 'INFO', iv you give it twice (or -vv), it will use 'DEBUG'. If you keep giving (verbose) the logging level will decrease in increments in 10, but those don't have canonical names, and would be up to the user to use at their volition. * Update pycbc/__init__.py Co-authored-by: Thomas Dent * Update __init__.py * Update __init__.py * Update pycbc/__init__.py Co-authored-by: Thomas Dent --------- Co-authored-by: Thomas Dent --- pycbc/__init__.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/pycbc/__init__.py b/pycbc/__init__.py index 53c35debfff..18276a6b630 100644 --- a/pycbc/__init__.py +++ b/pycbc/__init__.py @@ -78,8 +78,7 @@ def init_logging(verbose=False, format='%(asctime)s %(message)s'): What level to set the verbosity level to. Accepts either a boolean or an integer representing the level to set. If True/False will set to ``logging.INFO``/``logging.WARN``. For higher logging levels, pass - an integer representing the level to set (see the ``logging`` module - for details). Default is ``False`` (``logging.WARN``). + an integer representing the level to set. (1 = INFO, 2 = DEBUG). format : str, optional The format to use for logging messages. """ @@ -96,15 +95,11 @@ def sig_handler(signum, frame): signal.signal(signal.SIGUSR1, sig_handler) - if not verbose: - initial_level = logging.WARN - elif int(verbose) == 1: - initial_level = logging.INFO - else: - initial_level = int(verbose) - + # See https://docs.python.org/3/library/logging.html#levels + # for log level definitions logger = logging.getLogger() - logger.setLevel(initial_level) + verbose_int = 0 if verbose is None else int(verbose) + logger.setLevel(logging.WARNING - verbose_int * 10) # Initial setting sh = logging.StreamHandler() logger.addHandler(sh) sh.setFormatter(LogFormatter(fmt=format))