[wxPython-users] adding timestamp to crash log

John Fouhy john at fouhy.net
Wed Jul 19 19:42:50 PDT 2006


On 20/07/06, Thomas Thomas <thomas at eforms.co.nz> wrote:
> I am getting errors on application crash log
>
> eg:
> Traceback (most recent call last):
>   File "gui\mainFrame.pyc", line 3907, in OnAdvSearchBtnButton
>   File "gui\wxDialogAdvSearch.pyc", line 10, in create
>   File "gui\wxDialogAdvSearch.pyc", line 157, in __init__
>   File "gui\wxDialogAdvSearch.pyc", line 164, in setCurrentOfficeDetails
>   File "gui\wxDialogAdvSearch.pyc", line 179, in _populateCategoryList
> TypeError: iteration over non-sequence
> is it possible to add timestamp to these logs..

Yep.. You could try looking at sys.excepthook --- the interpreter
calls this whenever it hits an uncaught exception.  Maybe at a basic
level:

####
# Put this code somewhere in your app initialisation code.
# Untested!

import sys
import datetime

_excepthook = sys.excepthook
def myExceptHook(type, value, traceback):
    print datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S')
    _excepthook(type, value, traceback)
sys.excepthook = myExceptHook
####

sys.excepthook is documented here: http://docs.python.org/lib/module-sys.html.

Also check the Python Cookbook
(http://aspn.activestate.com/ASPN/Python/Cookbook/); there are several
recipes dealing with exception handling and printing trackbacks.

-- 
John.




More information about the wxpython-users mailing list