From c2cf591e1bdaa40641b7cd1c7c13122dfc7f191c Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 8 Aug 2017 17:17:57 +0530 Subject: [PATCH] Capture and log all Python warnings - Capture all Python warnings so that they can shown as part of logging system on console and in log file. - Also capture deprecation warnings into logging system if debug mode is enabled. Current versions of Python disable deprecation warnings by default. Django 1.11 also follows this approach now. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Johannes Keyser --- plinth/__main__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plinth/__main__.py b/plinth/__main__.py index 328484c17..d23a3d1a2 100644 --- a/plinth/__main__.py +++ b/plinth/__main__.py @@ -26,6 +26,7 @@ import logging import os import stat import sys +import warnings import cherrypy @@ -82,6 +83,15 @@ def setup_logging(): cherrypy.log.error_file = cfg.status_log_file cherrypy.log.access_file = cfg.access_log_file + # Capture all Python warnings such as deprecation warnings + logging.captureWarnings(True) + + # Log all deprecation warnings when in debug mode + if cfg.debug: + warnings.filterwarnings('default', '', DeprecationWarning) + warnings.filterwarnings('default', '', PendingDeprecationWarning) + warnings.filterwarnings('default', '', ImportWarning) + def setup_server(): """Setup CherryPy server"""