[Sugar-devel] [PATCH sugar v2 12/21] use logging.exception() instead of logging.error(traceback.format_exc())

Simon Schampijer simon at schampijer.de
Wed Nov 24 13:14:02 EST 2010


Reviewed-by: Simon Schampijer<simon at schampijer.de>


On 11/19/2010 10:13 PM, Sascha Silbe wrote:
> logging.exception() handles exceptions nicely for us, no need to explicitly
> use traceback.
>
> Reviewed-by: James Cameron<quozl at laptop.org>
> CC: Aleksey Lim<alsroot at member.fsf.org>
> Signed-off-by: Sascha Silbe<sascha-pgp at silbe.org>
>
> diff --git a/extensions/cpsection/updater/backends/aslo.py b/extensions/cpsection/updater/backends/aslo.py
> index 016e5e8..eec54b0 100644
> --- a/extensions/cpsection/updater/backends/aslo.py
> +++ b/extensions/cpsection/updater/backends/aslo.py
> @@ -129,7 +129,7 @@ class _UpdateFetcher(object):
>               try:
>                   version = int(document.find(_FIND_VERSION).text)
>               except ValueError:
> -                logging.error(traceback.format_exc())
> +                logging.exception('Exception occured while parsing version')
>                   version = 0
>
>               link = document.find(_FIND_LINK).text
> @@ -137,7 +137,7 @@ class _UpdateFetcher(object):
>               try:
>                   size = long(document.find(_FIND_SIZE).text) * 1024
>               except ValueError:
> -                logging.error(traceback.format_exc())
> +                logging.exception('Exception occured while parsing size')
>                   size = 0
>
>           global _fetcher
> diff --git a/src/jarabe/controlpanel/cmd.py b/src/jarabe/controlpanel/cmd.py
> index 4e5e8e8..fe8f1a4 100644
> --- a/src/jarabe/controlpanel/cmd.py
> +++ b/src/jarabe/controlpanel/cmd.py
> @@ -18,7 +18,6 @@ import sys
>   import getopt
>   import os
>   from gettext import gettext as _
> -import traceback
>   import logging
>
>   from jarabe import config
> @@ -69,8 +68,7 @@ def load_modules():
>                   module = __import__('.'.join(('cpsection', item, 'model')),
>                                       globals(), locals(), ['model'])
>               except Exception:
> -                logging.error('Exception while loading extension:\n' + \
> -                    ''.join(traceback.format_exception(*sys.exc_info())))
> +                logging.exception('Exception while loading extension:')
>               else:
>                   modules.append(module)
>
> diff --git a/src/jarabe/frame/devicestray.py b/src/jarabe/frame/devicestray.py
> index cecde8f..c5db639 100644
> --- a/src/jarabe/frame/devicestray.py
> +++ b/src/jarabe/frame/devicestray.py
> @@ -15,8 +15,6 @@
>   # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
>
>   import os
> -import sys
> -import traceback
>   import logging
>
>   from sugar.graphics import tray
> @@ -36,8 +34,7 @@ class DevicesTray(tray.HTray):
>                                        locals(), [module_name])
>                       mod.setup(self)
>                   except Exception:
> -                    logging.error('Exception while loading extension:\n' + \
> -                        ''.join(traceback.format_exception(*sys.exc_info())))
> +                    logging.exception('Exception while loading extension:')
>
>       def add_device(self, view):
>           index = 0
> diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py
> index 595a8ea..a33038a 100644
> --- a/src/jarabe/journal/journalactivity.py
> +++ b/src/jarabe/journal/journalactivity.py
> @@ -17,8 +17,6 @@
>
>   import logging
>   from gettext import gettext as _
> -import sys
> -import traceback
>   import uuid
>
>   import gtk
> @@ -230,8 +228,7 @@ class JournalActivity(JournalWindow):
>           try:
>               self._detail_toolbox.entry_toolbar.set_metadata(metadata)
>           except Exception:
> -            logging.error('Exception while displaying entry:\n' + \
> -                ''.join(traceback.format_exception(*sys.exc_info())))
> +            logging.exception('Exception while displaying entry:')
>
>           self.set_toolbar_box(self._detail_toolbox)
>           self._detail_toolbox.show()
> @@ -239,8 +236,7 @@ class JournalActivity(JournalWindow):
>           try:
>               self._detail_view.props.metadata = metadata
>           except Exception:
> -            logging.error('Exception while displaying entry:\n' + \
> -                ''.join(traceback.format_exception(*sys.exc_info())))
> +            logging.exception('Exception while displaying entry:')
>
>           self.set_canvas(self._secondary_view)
>           self._secondary_view.show()
> diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
> index 3c0ce7a..71124a4 100644
> --- a/src/jarabe/model/bundleregistry.py
> +++ b/src/jarabe/model/bundleregistry.py
> @@ -17,7 +17,6 @@
>
>   import os
>   import logging
> -import traceback
>
>   import gconf
>   import gobject
> @@ -208,19 +207,17 @@ class BundleRegistry(gobject.GObject):
>                   if os.path.isdir(bundle_dir):
>                       bundles[bundle_dir] = os.stat(bundle_dir).st_mtime
>               except Exception:
> -                logging.error('Error while processing installed activity ' \
> -                              'bundle %s:\n%s' % \
> -                                    (bundle_dir, traceback.format_exc()))
> +                logging.exception('Error while processing installed activity'
> +                                  ' bundle %s:', bundle_dir)
>
>           bundle_dirs = bundles.keys()
>           bundle_dirs.sort(lambda d1, d2: cmp(bundles[d1], bundles[d2]))
>           for folder in bundle_dirs:
>               try:
>                   self._add_bundle(folder)
> -            except Exception, e:
> -                logging.error('Error while processing installed activity ' \
> -                              'bundle %s:\n%s' % \
> -                                    (folder, traceback.format_exc()))
> +            except:
> +                logging.exception('Error while processing installed activity'
> +                                  ' bundle %s:', folder)
>
>       def add_bundle(self, bundle_path, install_mime_type=False):
>           bundle = self._add_bundle(bundle_path, install_mime_type)
> @@ -441,11 +438,10 @@ class BundleRegistry(gobject.GObject):
>               try:
>                   self.uninstall(bundle, force=True)
>               except Exception:
> -                logging.error('Uninstall failed, still trying to install ' \
> -                    'newer bundle:\n' + \
> -                    traceback.format_exc())
> +                logging.exception('Uninstall failed, still trying to install'
> +                                  ' newer bundle:')
>           else:
> -            logging.warning('Unable to uninstall system activity, ' \
> +            logging.warning('Unable to uninstall system activity, '
>                               'installing upgraded version in user activities')
>
>           self.install(bundle)
> diff --git a/src/jarabe/view/keyhandler.py b/src/jarabe/view/keyhandler.py
> index b2d96d3..cdea52c 100644
> --- a/src/jarabe/view/keyhandler.py
> +++ b/src/jarabe/view/keyhandler.py
> @@ -17,7 +17,6 @@
>
>   import os
>   import logging
> -import traceback
>
>   import dbus
>   import gtk
> @@ -100,8 +99,7 @@ class KeyHandler(object):
>                               raise ValueError('Key %r is already bound' % key)
>                           _actions_table[key] = module
>                   except Exception:
> -                    logging.error('Exception while loading extension:\n' + \
> -                                  traceback.format_exc())
> +                    logging.exception('Exception while loading extension:')
>
>           self._key_grabber.grab_keys(_actions_table.keys())
>
> diff --git a/src/jarabe/view/viewsource.py b/src/jarabe/view/viewsource.py
> index 32446e6..a1c0be3 100644
> --- a/src/jarabe/view/viewsource.py
> +++ b/src/jarabe/view/viewsource.py
> @@ -17,7 +17,6 @@
>
>   import os
>   import logging
> -import traceback
>   from gettext import gettext as _
>
>   import gobject
> @@ -54,9 +53,9 @@ def setup_view_source(activity):
>               expected_exceptions = ['org.freedesktop.DBus.Error.UnknownMethod',
>                       'org.freedesktop.DBus.Python.NotImplementedError']
>               if e.get_dbus_name() not in expected_exceptions:
> -                logging.error(traceback.format_exc())
> +                logging.exception('Exception occured in HandleViewSource():')
>           except Exception:
> -            logging.error(traceback.format_exc())
> +            logging.exception('Exception occured in HandleViewSource():')
>
>       window_xid = activity.get_xid()
>       if window_xid is None:
> @@ -78,9 +77,9 @@ def setup_view_source(activity):
>               expected_exceptions = ['org.freedesktop.DBus.Error.UnknownMethod',
>                       'org.freedesktop.DBus.Python.NotImplementedError']
>               if e.get_dbus_name() not in expected_exceptions:
> -                logging.error(traceback.format_exc())
> +                logging.exception('Exception occured in GetDocumentPath():')
>           except Exception:
> -            logging.error(traceback.format_exc())
> +            logging.exception('Exception occured in GetDocumentPath():')
>
>       if bundle_path is None and document_path is None:
>           _logger.debug('Activity without bundle_path nor document_path')



More information about the Sugar-devel mailing list