From 6e315303de435b602fa479f040e1754ed9795e2f Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 25 Oct 2021 11:27:57 -0700 Subject: [PATCH] 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. --- voussoirkit/vlogging.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/voussoirkit/vlogging.py b/voussoirkit/vlogging.py index 28dbdeb..9a16067 100644 --- a/voussoirkit/vlogging.py +++ b/voussoirkit/vlogging.py @@ -35,6 +35,13 @@ def add_loud(log): addLevelName(LOUD, 'LOUD') 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): ''' 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: return - handler = StreamHandler() - handler.setFormatter(Formatter('{levelname}:{name}:{message}', style='{')) - handler.setLevel(level) - root.addHandler(handler) + add_root_handler(level) + +def basic_config_by_argv(argv): + ''' + 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): ''' @@ -153,18 +166,7 @@ def main_decorator(main): changes to your argparser. ''' def wrapped(argv): - argv = main_level_by_argv(argv) + (level, argv) = get_level_by_argv(argv) + add_root_handler(level) return main(argv) 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