From: Christian Herdtweck Date: Fri, 9 Aug 2019 13:19:00 +0000 (+0200) Subject: Add a NullHandler if no handler is supplied to i2n logger X-Git-Tag: v1.6.7~1^2~4 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=4767d1907c8e91ba746f2ce5949332ba0f9c925e;p=pyi2ncommon Add a NullHandler if no handler is supplied to i2n logger --- 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