Finally solve vlogging/opnot interplay by just setting NOTSET always.
This commit is contained in:
parent
d38c7c074e
commit
d082a0fbb5
2 changed files with 9 additions and 19 deletions
|
@ -243,13 +243,6 @@ def main_decorator(subject, *, log_return_value=True, **kwargs):
|
|||
(argv, level) = get_level_by_argv(argv)
|
||||
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):
|
||||
return main(argv)
|
||||
|
||||
|
|
|
@ -12,6 +12,15 @@ from logging import *
|
|||
|
||||
_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
|
||||
SILENT = 99999999999
|
||||
|
||||
|
@ -45,18 +54,6 @@ def basic_config(level):
|
|||
This adds a handler with the given level to the root logger, but only
|
||||
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.setFormatter(Formatter('{levelname}:{name}:{message}', style='{'))
|
||||
handler.setLevel(level)
|
||||
|
|
Loading…
Reference in a new issue