adding timestamp to crash log

Hi All,

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…

And what the best way of handling iteration over non-sequence

try:

for item in sequence:

    print item

except TypeError:
print e

cheers

Thomas

···

Thomas Thomas

phone +64 7 855 8478
fax +64 7 855 8871

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

···

On 20/07/06, Thomas Thomas <thomas@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..

####
# 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: sys — System-specific parameters and functions — Python 3.13.0 documentation.

Also check the Python Cookbook
(ActiveState Community - Boosting coder and team productivity with ready-to-use open source languages and tools.); there are several
recipes dealing with exception handling and printing trackbacks.

--
John.