Add global ARGV_LEVEL for runtime use.

This commit is contained in:
voussoir 2022-04-30 07:22:18 -07:00
parent 19f69473c8
commit fa78fa3b9d
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -38,6 +38,7 @@ root.setLevel(NOTSET)
LOUD = 1
SILENT = 99999999999
ARGV_LEVEL = NOTSET
_did_earlybird = False
def add_loud(log):
@ -208,12 +209,14 @@ def main_decorator(main):
betterhelp.HELPTEXT_EPILOGUES.add(BETTERHELP_EPILOGUE)
@functools.wraps(main)
def wrapped(argv, *args, **kwargs):
global ARGV_LEVEL
# The reason we don't call basic_config is that another module may have
# attached a root handler for another purpose.
# However we do check _did_earlybird so that we don't get double
# handlers from this module.
if not _did_earlybird:
(level, argv) = get_level_by_argv(argv)
ARGV_LEVEL = level
add_root_handler(level)
return main(argv, *args, **kwargs)
return wrapped