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

dwlehman installerbot-noreply at redhat.com
Thu Jun 25 21:56:08 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 e2afc16..43e5ff7 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 cf329f9..97ca3b5 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/a54d2d7689635c4b4cb3e1d1b791e05d524b379b


More information about the anaconda-patches mailing list