Blame SOURCES/sos-bz1026962-sosreport-log-plugin-exceptions-to-file.patch

e75bc7
From 8b49485153cc7dc03cd974dbc3a100c81ef04720 Mon Sep 17 00:00:00 2001
e75bc7
From: "Bryn M. Reeves" <bmr@redhat.com>
e75bc7
Date: Mon, 19 Jan 2015 19:40:06 +0000
e75bc7
Subject: [PATCH] [sosreport] log plugin exceptions to a file
e75bc7
e75bc7
Add exception logging for the Plugin.postproc() method and move
e75bc7
plugin exceptions into a separate per-plugin log file. This is
e75bc7
less cluttered than pushing a multi-line traceback through the
e75bc7
soslog.error logger and matches the behaviour of older releases.
e75bc7
e75bc7
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
e75bc7
---
e75bc7
 sos/sosreport.py | 17 +++++++++++++----
e75bc7
 1 file changed, 13 insertions(+), 4 deletions(-)
e75bc7
e75bc7
diff --git a/sos/sosreport.py b/sos/sosreport.py
e75bc7
index 3c0397c..f17194a 100644
e75bc7
--- a/sos/sosreport.py
e75bc7
+++ b/sos/sosreport.py
e75bc7
@@ -1071,8 +1071,14 @@ class SoSReport(object):
e75bc7
                 self.ui_log.info("")
e75bc7
                 self._exit()
e75bc7
 
e75bc7
-    def _log_plugin_exception(self, plugin_name):
e75bc7
-        self.soslog.error("%s\n%s" % (plugin_name, traceback.format_exc()))
e75bc7
+    def _log_plugin_exception(self, plugin, method):
e75bc7
+        trace = traceback.format_exc()
e75bc7
+        msg = "caught exception in plugin method"
e75bc7
+        plugin_err_log = "%s-plugin-errors.txt" % plugin
e75bc7
+        logpath = os.path.join(self.logdir, plugin_err_log)
e75bc7
+        self.soslog.error('%s "%s.%s()"' % (msg, plugin, method))
e75bc7
+        self.soslog.error('writing traceback to %s' % logpath)
e75bc7
+        self.archive.add_string("%s\n" % trace, logpath)
e75bc7
 
e75bc7
     def prework(self):
e75bc7
         self.policy.pre_work()
e75bc7
@@ -1129,7 +1135,7 @@ class SoSReport(object):
e75bc7
                 if self.raise_plugins:
e75bc7
                     raise
e75bc7
                 else:
e75bc7
-                    self._log_plugin_exception(plugname)
e75bc7
+                    self._log_plugin_exception(plugname, "setup")
e75bc7
 
e75bc7
     def version(self):
e75bc7
         """Fetch version information from all plugins and store in the report
e75bc7
@@ -1175,7 +1181,7 @@ class SoSReport(object):
e75bc7
                 if self.raise_plugins:
e75bc7
                     raise
e75bc7
                 else:
e75bc7
-                    self._log_plugin_exception(plugname)
e75bc7
+                    self._log_plugin_exception(plugname, "collect")
e75bc7
         self.ui_log.info("")
e75bc7
 
e75bc7
     def report(self):
e75bc7
@@ -1321,6 +1327,9 @@ class SoSReport(object):
e75bc7
             except:
e75bc7
                 if self.raise_plugins:
e75bc7
                     raise
e75bc7
+                else:
e75bc7
+                    self._log_plugin_exception(plugname, "postproc")
e75bc7
+
e75bc7
 
e75bc7
     def final_work(self):
e75bc7
         # this must come before archive creation to ensure that log
e75bc7
-- 
e75bc7
1.9.3
e75bc7