Blame SOURCES/0043-sosreport-log-plugin-exceptions-to-a-file.patch

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