[master 1/3] Log python warnings, including DeprecationWarning.

dwlehman installerbot-noreply at redhat.com
Mon Jun 29 18:21:40 UTC 2015


From: David Lehman <dlehman at redhat.com>

---
 blivet/__init__.py | 8 ++++++++
 blivet/util.py     | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/blivet/__init__.py b/blivet/__init__.py
index 5818bc9..8973dd2 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -51,6 +51,7 @@ def cb(self, exn):
 
 import sys
 import importlib
+import warnings
 
 from . import util, arch
 from .flags import flags
@@ -59,6 +60,13 @@ def cb(self, exn):
 log = logging.getLogger("blivet")
 program_log = logging.getLogger("program")
 
+# Tell the warnings module not to ignore DeprecationWarning, which it does by
+# default since python-2.7.
+warnings.simplefilter('module', DeprecationWarning)
+
+# Enable logging of python warnings.
+logging.captureWarnings(True)
+
 # XXX: respect the level? Need to translate between C and Python log levels.
 log_bd_message = lambda level, msg: program_log.info(msg)
 
diff --git a/blivet/util.py b/blivet/util.py
index 9400f82..db1887b 100644
--- a/blivet/util.py
+++ b/blivet/util.py
@@ -518,6 +518,11 @@ def set_up_logging(log_file='/tmp/blivet.log'):
     handler.setFormatter(formatter)
     log.addHandler(handler)
     program_log.addHandler(handler)
+
+    # capture python warnings in our logs
+    warning_log = logging.getLogger("py.warnings")
+    warning_log.addHandler(handler)
+
     log.info("sys.argv = %s", sys.argv)
 
 def create_sparse_tempfile(name, size):


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/794d3448e5a327ca82b9344025c32fd032814bfd


More information about the anaconda-patches mailing list