From ea97dcd015a4e5805302708cc30343b9f0771ce8 Mon Sep 17 00:00:00 2001 From: Richard Taylor Date: Fri, 6 Jan 2006 15:23:28 +0000 Subject: [PATCH] integration of logging framework svn: r5680 --- ChangeLog | 3 +++ src/gramps.py | 59 ++++++++++++++++++++++++++++++++++++++++++---- src/gramps_main.py | 6 +++-- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9af4d3d33..79388b063 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2006-01-06 Richard Taylor + * src/gramps.py, src/gramps_main.py: integration of logging framework. + 2006-01-06 Richard Taylor * test/GrampsLogger/ErrorReportAssistant_Test.py: added unittest for ErrorReportAssistant diff --git a/src/gramps.py b/src/gramps.py index c59f4b33c..c1e32edef 100755 --- a/src/gramps.py +++ b/src/gramps.py @@ -28,6 +28,9 @@ import os import locale import signal import gettext +import logging + +log = logging.getLogger(".") #------------------------------------------------------------------------- # @@ -85,8 +88,57 @@ signal.signal(signal.SIGCHLD, signal.SIG_DFL) args = sys.argv +def setup_logging(): + """Setup basic logging support.""" + + import logging + from GrampsLogger import RotateHandler, GtkHandler + + # Setup a formatter + form = logging.Formatter(fmt="%(relativeCreated)d: %(levelname)s: %(filename)s: line %(lineno)d: %(message)s") + + # Create the log handlers + rh = RotateHandler(capacity=20) + rh.setFormatter(form) + + # Only error and critical log records should + # trigger the GUI handler. + gtkh = GtkHandler(rotate_handler=rh) + gtkh.setFormatter(form) + gtkh.setLevel(logging.ERROR) + + stderrh = logging.StreamHandler(sys.stderr) + stderrh.setFormatter(form) + stderrh.setLevel(logging.DEBUG) + + # Setup the base level logger, this one gets + # everything. + l = logging.getLogger() + l.setLevel(logging.DEBUG) + l.addHandler(rh) + l.addHandler(gtkh) + l.addHandler(stderrh) + + # put a hook on to catch any completly unhandled exceptions. + def exc_hook(type, value, tb): + import traceback + log.error("Unhandled exception\n" + + "".join(traceback.format_exception(type, value, tb))) + + sys.excepthook = exc_hook + def run(): - try: + + try: + setup_logging() + except: + # If logging can't be started fall back on + # old exception display + import DisplayTrace + DisplayTrace.DisplayTrace() + + + try: import gnome self.program = gnome.program_init('gramps',const.version, gnome.libgnome_module_info_get(), @@ -102,7 +154,7 @@ def run(): except: pass - try: + try: import StartupDialog if StartupDialog.need_to_run(): @@ -110,8 +162,7 @@ def run(): else: gramps_main.Gramps(args) except: - import DisplayTrace - DisplayTrace.DisplayTrace() + log.error("Gramps failed to start.", exc_info=True) gobject.timeout_add(100, run, priority=100) gtk.main() diff --git a/src/gramps_main.py b/src/gramps_main.py index ec54f1aee..3ebad666d 100755 --- a/src/gramps_main.py +++ b/src/gramps_main.py @@ -26,6 +26,9 @@ # #------------------------------------------------------------------------- import gtk +import logging + +log = logging.getLogger(".") #------------------------------------------------------------------------- # @@ -98,7 +101,7 @@ def register_stock_icons (): icon_set = gtk.IconSet (pixbuf) factory.add (data[0], icon_set) else: - print 'failed to load GTK logo for toolbar' + log.debug('failed to load GTK logo for toolbar') class Gramps: """ @@ -109,7 +112,6 @@ class Gramps: """ def __init__(self,args): - try: GrampsCfg.loadConfig() self.welcome()