Add a NullHandler if no handler is supplied to i2n logger
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 9 Aug 2019 13:19:00 +0000 (15:19 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 10 Nov 2021 09:28:29 +0000 (10:28 +0100)
src/log_helpers.py

index 39e1f41..e416bea 100644 (file)
@@ -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