integration of logging framework

svn: r5680
This commit is contained in:
Richard Taylor 2006-01-06 15:23:28 +00:00
parent d62d7ae447
commit ea97dcd015
3 changed files with 62 additions and 6 deletions

View File

@ -1,3 +1,6 @@
2006-01-06 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
* src/gramps.py, src/gramps_main.py: integration of logging framework.
2006-01-06 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
* test/GrampsLogger/ErrorReportAssistant_Test.py: added unittest for
ErrorReportAssistant

View File

@ -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()

View File

@ -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()