Logging with wxPython?

Hello all,

I’ve got an app that I now want to add some logging to. I’ve had problems user user crashes and having a log file would be very handy.

I’ve tried to play around with the wxLog functions w/o success. Looking in the archive I found http://lists.wxwidgets.org/archive/wxPython-users/msg06432.html which implies that at one time, long ago, the wxLog stuff wasn’t in wxPython. I tried to use wxLogStderr() with a file pointer and it kept blowing up.

I’ve also tried to look at the wiki, but the only logging stuff I found was on http://wiki.wxpython.org/index.cgi/iPodder?highlight=%28logging%29
and that looks like it’s using the Python logging module.

I can use the built in logging module but was wondering what other people were doing. Is the assumption that since we have the logging module in Python we should just use that? If so, is there a reasonable way to attach the log to the application so classes can query to see if there is a valid log in use? (IE: can I attach the logger to my wx.App class and use getattr() to see if ‘pyLog’ is there?

Thanks!

···


“A little government and a little luck are necessary in life, but only a fool trusts either of them.” – P. J. O’Rourke

Hi Chris,

Chris Cioffi wrote:

Hello all,

I've got an app that I now want to add some logging to. I've had problems user user crashes and having a log file would be very handy.

I've tried to play around with the wxLog functions w/o success. Looking in the archive I found http://lists.wxwidgets.org/archive/wxPython-users/msg06432.html which implies that at one time, long ago, the wxLog stuff wasn't in wxPython. I tried to use wxLogStderr() with a file pointer and it kept blowing up.

I've also tried to look at the wiki, but the only logging stuff I found was on http://wiki.wxpython.org/index.cgi/iPodder?highlight=(logging) and that looks like it's using the Python logging module.

I can use the built in logging module but was wondering what other people were doing. Is the assumption that since we have the logging module in Python we should just use that? If so, is there a reasonable way to attach the log to the application so classes can query to see if there is a valid log in use? (IE: can I attach the logger to my wx.App class and use getattr() to see if 'pyLog' is there?

I don't know what the best way is, but I am sure others will give you pointers.

What I do:
- on application start redirect stdout and stderr to some log files, I do it in the application folder as my app is single user, one should probably put it into some user specific folder.
- I also use "sys.excepthook = self.MyExceptionHandler" and MyExceptionHandler writes stuff to stderr log and adds a date and time stamp to the errors and then puts up a dialog from which the user can e-mail me the log files (stdout, stderr and sqllog), the email gives me information on the version the user runs, what os they are using and allows them to enter some description.

The error dialog is also put up on opening and closing of the application if the error logs are not empty.

You might also want to the check the archive of this list as there have been discussions about this before. In particular in the following threads, but I am sure there are others:

- Have wxPython global exception handling tool ?
- Catching *all* exceptions...
- own handling of uncaught exceptions in Python code

Hope this helps
Werner

···

Thanks!
--
"A little government and a little luck are necessary in life, but only a fool trusts either of them." -- P. J. O'Rourke

Chris Cioffi wrote:

Hello all,

I've got an app that I now want to add some logging to. I've had problems user user crashes and having a log file would be very handy.

I've tried to play around with the wxLog functions w/o success. Looking in the archive I found http://lists.wxwidgets.org/archive/wxPython-users/msg06432.html which implies that at one time, long ago, the wxLog stuff wasn't in wxPython. I tried to use wxLogStderr() with a file pointer and it kept blowing up.

I've also tried to look at the wiki, but the only logging stuff I found was on http://wiki.wxpython.org/index.cgi/iPodder?highlight=(logging) and that looks like it's using the Python logging module.

I can use the built in logging module but was wondering what other people were doing. Is the assumption that since we have the logging module in Python we should just use that?

It's there now and has been since before Python had a standard logging module. Take a look at the Main.py module of the demo for an example of a custom wx.Log class.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Ah, so if I look in the obvious place instead of the docs I would find exactly what I want! :slight_smile: Just a note: I’ve found about 80% of what I needed from wxPython in the demo and I’m still amazed that there’s always more to learn from it.

Thanks Robin! :slight_smile:

···

On 5/11/06, Robin Dunn robin@alldunn.com wrote:

Chris Cioffi wrote:
[snip]

I can use the built in logging module but was wondering what other
people were doing. Is the assumption that since we have the logging
module in Python we should just use that?

It’s there now and has been since before Python had a standard logging
module. Take a look at the Main.py module of the demo for an example of
a custom wx.Log class.


“A little government and a little luck are necessary in life, but only a fool trusts either of them.” – P. J. O’Rourke