Finally finally fix vlogging/operatornotify interplay?

I realized that vlogging.main_decorator shouldn't be using basic_config
in the first place because main decorator should always create a stderr
handler and I was just contorting the previous code to make that happen
via basic_config. So instead let's just add it ourselves.
master
voussoir 2021-10-25 11:27:57 -07:00
parent 414fc60f48
commit 6e315303de
No known key found for this signature in database
GPG Key ID: 5F7554F8C26DACCB
1 changed files with 19 additions and 17 deletions

View File

@ -35,6 +35,13 @@ def add_loud(log):
addLevelName(LOUD, 'LOUD') addLevelName(LOUD, 'LOUD')
log.loud = loud.__get__(log, log.__class__) log.loud = loud.__get__(log, log.__class__)
def add_root_handler(level):
handler = StreamHandler()
handler.setFormatter(Formatter('{levelname}:{name}:{message}', style='{'))
handler.setLevel(level)
root.addHandler(handler)
return handler
def basic_config(level): def basic_config(level):
''' '''
This adds a handler with the given level to the root logger, but only This adds a handler with the given level to the root logger, but only
@ -43,10 +50,16 @@ def basic_config(level):
if root.handlers: if root.handlers:
return return
handler = StreamHandler() add_root_handler(level)
handler.setFormatter(Formatter('{levelname}:{name}:{message}', style='{'))
handler.setLevel(level) def basic_config_by_argv(argv):
root.addHandler(handler) '''
This function does basic_config with a level set by the flags in argv, then
returns the rest of argv which you can pass to your argparser.
'''
(level, argv) = get_level_by_argv(argv)
basic_config(level)
return argv
def get_level_by_argv(argv): def get_level_by_argv(argv):
''' '''
@ -153,18 +166,7 @@ def main_decorator(main):
changes to your argparser. changes to your argparser.
''' '''
def wrapped(argv): def wrapped(argv):
argv = main_level_by_argv(argv) (level, argv) = get_level_by_argv(argv)
add_root_handler(level)
return main(argv) return main(argv)
return wrapped return wrapped
def main_level_by_argv(argv):
'''
This function puts a handler on the root logger with a level set by the
flags in argv, then returns the rest of argv which you can pass to
your argparser.
'''
(level, argv) = get_level_by_argv(argv)
basic_config(level)
return argv