[blivet:master] When logging, indicate whether exception was ignored by blivet.

mulhern amulhern at redhat.com
Thu Jun 26 20:46:05 UTC 2014


Other tools examine the log to determine if there was a failure. The
IGNORED flag indicates that, while there was a traceback, blivet felt
able to ignore it, and so the tools should not treat the existance of this
traceback as a sign of failure.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/storage_log.py | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/blivet/storage_log.py b/blivet/storage_log.py
index 0609d0b..6ee694c 100644
--- a/blivet/storage_log.py
+++ b/blivet/storage_log.py
@@ -46,27 +46,32 @@ def log_method_return(d, retval):
     fmt_args = (spaces, classname, methodname, retval)
     log.debug(fmt, *fmt_args)
 
-def log_exception_info(log_func=log.debug, fmt_str=None, fmt_args=None):
+def log_exception_info(log_func=log.debug, fmt_str=None, fmt_args=None, ignored=True):
     """Log detailed exception information.
 
        :param log_func: the desired logging function
        :param str fmt_str: a format string for any additional message
        :param fmt_args: arguments for the format string
        :type fmt_args: a list of str
+       :param bool ignored: True if no action is taken regarding the exception
 
        Note: the logging function indicates the severity level of
        this exception according to the calling function. log.debug,
        the default, is the lowest level.
+
+       Note: If the ignored flag is set, each line of the exception information
+       is prepended with an 'IGNORED' prefix.
     """
     fmt_args = fmt_args or []
     (_methodname, depth) = function_name_and_depth()
-    spaces = depth * ' '
-    log_func("%sCaught exception, continuing.", spaces)
+    indent = depth * ' '
+    prefix = 'IGNORED:' + indent if ignored else indent
+    log_func("%sCaught exception, continuing.", prefix)
     if fmt_str:
         fmt_str = "%sProblem description: " + fmt_str
-        log_func(fmt_str, spaces, *fmt_args)
-    log_func("%sBegin exception details.", spaces)
+        log_func(fmt_str, prefix, *fmt_args)
+    log_func("%sBegin exception details.", prefix)
     tb = traceback.format_exception(*sys.exc_info())
     for line in (l.rstrip() for entry in tb for l in entry.split("\n") if l):
-        log_func("%s    %s", spaces, line)
-    log_func("%sEnd exception details.", spaces)
+        log_func("%s    %s", prefix, line)
+    log_func("%sEnd exception details.", prefix)
-- 
1.9.3



More information about the anaconda-patches mailing list