Finally solve vlogging/opnot interplay by just setting NOTSET always.

master
voussoir 2021-10-18 18:20:17 -07:00
parent d38c7c074e
commit d082a0fbb5
No known key found for this signature in database
GPG Key ID: 5F7554F8C26DACCB
2 changed files with 9 additions and 19 deletions

View File

@ -243,13 +243,6 @@ def main_decorator(subject, *, log_return_value=True, **kwargs):
(argv, level) = get_level_by_argv(argv) (argv, level) = get_level_by_argv(argv)
context = main_log_context(subject, level, **kwargs) context = main_log_context(subject, level, **kwargs)
# We need to call basic_config so that operatornotify's logs have
# somewhere to go. We do this only during wrapped, not before, so
# that if the main also has vlogging.main_decorator or any other
# decorators that will prepare the logging before main is called,
# this shouldn't interfere with those.
vlogging.basic_config(vlogging.INFO)
if isinstance(context, contextlib.nullcontext): if isinstance(context, contextlib.nullcontext):
return main(argv) return main(argv)

View File

@ -12,6 +12,15 @@ from logging import *
_getLogger = getLogger _getLogger = getLogger
# Python gives the root logger a level of WARNING. The problem is that prevents
# any handlers you add to it from receiving lower level messages. WARNING might
# be fine for the stderr handler, but you might like to have a log file
# containing everything including info and debug.
# I find that logging works best if the root logger itself doesn't have a level
# and the handlers can choose what they want.
root = getLogger()
root.setLevel(NOTSET)
LOUD = 1 LOUD = 1
SILENT = 99999999999 SILENT = 99999999999
@ -45,18 +54,6 @@ 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
if it has no handlers yet. if it has no handlers yet.
''' '''
# Previously I was using basicConfig to prepare the handlers and then
# setting root.setLevel, but the problem is that prevents any other
# handlers on the root from receiving messages at a lower level.
# It works best if the logger itself doesn't have a level and the handlers
# can choose what they want.
root = getLogger()
if root.handlers:
return
root.setLevel(NOTSET)
handler = StreamHandler() handler = StreamHandler()
handler.setFormatter(Formatter('{levelname}:{name}:{message}', style='{')) handler.setFormatter(Formatter('{levelname}:{name}:{message}', style='{'))
handler.setLevel(level) handler.setLevel(level)