Connect root logger to null handler by default

In the default logging config, create a NullHandler logging handler
and connect the root logger to that.

Starting in python 3.2[1], a logging handler of last resort will output
exceptions to stderr if no handlers are configured.  Currently, our
default logging configuration has no handlers configured for the
root logger, and therefore libraries which log errors or exceptions
on loggers that do not appear in our configuration will use the logger
of last resort.

This is the case for paramiko.  During our key scanning, we now expect
paramiko to raise some exceptions about some host keys being invalid.
We have an exception handler to avoid logging the exception when it is
raised to us, however, paramiko also logs the exception under its own
namespace before raising it.  In order to suppress the output of these
exceptions, we need to ensure that paramiko logs have a handler.  The
easiest way to do that for paramiko and other libraries is by routing
the root logger to null, which was our original intent.

[1] https://docs.python.org/3/howto/logging.html#what-happens-if-no-configuration-is-provided

Change-Id: Iaa57ed0f0452eefd376a68ac21f49f3141cdaa25
This commit is contained in:
James E. Blair 2021-01-30 10:21:57 -08:00
parent bd6dea8f97
commit 12d128c170
1 changed files with 4 additions and 1 deletions

View File

@ -36,6 +36,9 @@ _DEFAULT_SERVER_LOGGING_CONFIG = {
'level': 'INFO',
'formatter': 'simple',
},
'null': {
'class': 'logging.NullHandler',
}
},
'loggers': {
'nodepool': {
@ -55,7 +58,7 @@ _DEFAULT_SERVER_LOGGING_CONFIG = {
'level': 'WARN',
},
},
'root': {'handlers': []},
'root': {'handlers': ['null']},
}
_DEFAULT_SERVER_FILE_HANDLERS = {