From 12d128c170a0013f8f66c9d5f2d7f6f32d0194d2 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Sat, 30 Jan 2021 10:21:57 -0800 Subject: [PATCH] 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 --- nodepool/logconfig.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nodepool/logconfig.py b/nodepool/logconfig.py index 71b3d4e92..d8cbc0da8 100644 --- a/nodepool/logconfig.py +++ b/nodepool/logconfig.py @@ -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 = {