integration of logging framework
svn: r5680
This commit is contained in:
parent
767b22bd17
commit
c3b6a03856
@ -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>
|
2006-01-06 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
|
||||||
* test/GrampsLogger/ErrorReportAssistant_Test.py: added unittest for
|
* test/GrampsLogger/ErrorReportAssistant_Test.py: added unittest for
|
||||||
ErrorReportAssistant
|
ErrorReportAssistant
|
||||||
|
@ -28,6 +28,9 @@ import os
|
|||||||
import locale
|
import locale
|
||||||
import signal
|
import signal
|
||||||
import gettext
|
import gettext
|
||||||
|
import logging
|
||||||
|
|
||||||
|
log = logging.getLogger(".")
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -85,7 +88,56 @@ signal.signal(signal.SIGCHLD, signal.SIG_DFL)
|
|||||||
|
|
||||||
args = sys.argv
|
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():
|
def run():
|
||||||
|
|
||||||
|
try:
|
||||||
|
setup_logging()
|
||||||
|
except:
|
||||||
|
# If logging can't be started fall back on
|
||||||
|
# old exception display
|
||||||
|
import DisplayTrace
|
||||||
|
DisplayTrace.DisplayTrace()
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import gnome
|
import gnome
|
||||||
self.program = gnome.program_init('gramps',const.version,
|
self.program = gnome.program_init('gramps',const.version,
|
||||||
@ -110,8 +162,7 @@ def run():
|
|||||||
else:
|
else:
|
||||||
gramps_main.Gramps(args)
|
gramps_main.Gramps(args)
|
||||||
except:
|
except:
|
||||||
import DisplayTrace
|
log.error("Gramps failed to start.", exc_info=True)
|
||||||
DisplayTrace.DisplayTrace()
|
|
||||||
|
|
||||||
gobject.timeout_add(100, run, priority=100)
|
gobject.timeout_add(100, run, priority=100)
|
||||||
gtk.main()
|
gtk.main()
|
||||||
|
@ -26,6 +26,9 @@
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import gtk
|
import gtk
|
||||||
|
import logging
|
||||||
|
|
||||||
|
log = logging.getLogger(".")
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -98,7 +101,7 @@ def register_stock_icons ():
|
|||||||
icon_set = gtk.IconSet (pixbuf)
|
icon_set = gtk.IconSet (pixbuf)
|
||||||
factory.add (data[0], icon_set)
|
factory.add (data[0], icon_set)
|
||||||
else:
|
else:
|
||||||
print 'failed to load GTK logo for toolbar'
|
log.debug('failed to load GTK logo for toolbar')
|
||||||
|
|
||||||
class Gramps:
|
class Gramps:
|
||||||
"""
|
"""
|
||||||
@ -109,7 +112,6 @@ class Gramps:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,args):
|
def __init__(self,args):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
GrampsCfg.loadConfig()
|
GrampsCfg.loadConfig()
|
||||||
self.welcome()
|
self.welcome()
|
||||||
|
Loading…
Reference in New Issue
Block a user