From 4767d1907c8e91ba746f2ce5949332ba0f9c925e Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Fri, 9 Aug 2019 15:19:00 +0200 Subject: [PATCH] Add a NullHandler if no handler is supplied to i2n logger --- src/log_helpers.py | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/src/log_helpers.py b/src/log_helpers.py index 39e1f41..e416bea 100644 --- a/src/log_helpers.py +++ b/src/log_helpers.py @@ -180,6 +180,7 @@ class I2nLogger: (assumes one line per call to log/debug/info/notice/..., only counts calls with priority above this logger's level) * provides shorter method names: dbg, note, warn, err + * adds a NullHandler if `streams` and `files` and `handlers` are all `None` ..note:: Creating multiple instances with the same name is not allowed and will result in an error. Use :py:func:`get_logger` instead of this @@ -268,6 +269,9 @@ class I2nLogger: handler.setLevel(self._level) self._log.addHandler(handler) + if not self._log.handlers: + self._log.addHandler(logging.NullHandler()) + # remember that this logger is a I2nLogger _i2n_loggers[name] = self -- 1.7.1