jenkins-bot merged this change.
logging.py: Add a last resort logging handler for python 2
Python 3 loggers already have a lastResort handler.[1] This patch adds a
similar one for them in Python 2.
The config uses the warning logger, but its handler is not initialized at
that point. Loggers get initialized inside bot.py, but we cannot use those
initializer inside config2.py because of circular dependency issue.
[1]: https://docs.python.org/3.2/library/logging.html#logging.lastResort
Bug: T188417
Change-Id: I24ce4de6c4bec5ece6401aa14227add713c60659
---
M pywikibot/logging.py
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/pywikibot/logging.py b/pywikibot/logging.py
index e576d3b..fe66905 100644
--- a/pywikibot/logging.py
+++ b/pywikibot/logging.py
@@ -12,7 +12,8 @@
import sys
# logging levels
-from logging import DEBUG, INFO, WARNING, ERROR, CRITICAL
+from logging import DEBUG, INFO, WARNING, ERROR, CRITICAL, StreamHandler
+
STDOUT = 16
VERBOSE = 18
INPUT = 25
@@ -73,6 +74,9 @@
else:
logger = logging.getLogger("pywiki")
+ if not logger.handlers: # lastResort for Python 2 (T188417)
+ logger.handlers.append(StreamHandler())
+
# invoke any init routines
if _init_routines:
_init()
To view, visit change 415248. To unsubscribe, visit settings.