Skip to content

Commit

Permalink
Update __init__.py (gwastro#4564)
Browse files Browse the repository at this point in the history
* 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 <thomas.dent@usc.es>

* Update __init__.py

* Update __init__.py

* Update pycbc/__init__.py

Co-authored-by: Thomas Dent <thomas.dent@usc.es>

---------

Co-authored-by: Thomas Dent <thomas.dent@usc.es>
  • Loading branch information
2 people authored and bhooshan-gadre committed Dec 19, 2023
1 parent 8f3be25 commit da9f23a
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions pycbc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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))
Expand Down

0 comments on commit da9f23a

Please sign in to comment.