Logging Strategies

Good day all,

I'm thinking it may be beneficial to sprinkle some debug logging throughout my app (a painting-type program), and to have this info written to a file. My current debugging strategy is to hook up a custom exception listener (sys.excepthook) and to allow the user to e-mail me a copy of the stack trace that caused the crash.

This has been pretty handy at seeing what the user's done to cause the program to crash, but I feel that a log file could certainly help.
I'm wondering what the best way to do this is. I'm thinking of enabling logging via a command-line switch and to create a log per "run" of the program, and to e-mail myself a copy of the log when a crash occurs. However, the log's won't help if the app's not in debug mode!

I'm a little worried of the log filling up too fast - if I place logging inside some mouse motion event handlers, then it'll create many entries. Also, a log file may grow pretty large, and just be filled with irrelevant information to me when examining a bug report.

How do you guys deal with this? Do you use wx's logging facilities or the standard python module? Can you offer me any hints. Thanks.

···

--
Steven Sproat, BSc
http://www.whyteboard.org/

I’m curious to hear what others do for logging myself. At one point I was putting func(…, …, log=text) in most of my function parms as seen in wxPython Demo. text would be a callable. It worked ok

I’ve made a bunch of (incomplete) little logger apps playing around with ideas.

First thing I did was create a function that replaces all my print statements and print functions. I named the callable “text” but probably should have called it “textout”. text.active = True or False can turn off all textual printing. But the different loggers I’ve written all use text() instead of print or print(). All the loggers I did have something like an “IsActive” attribute that I turn on or off.

Second thing I tried was created a module with 5 or so functions named log, deblog, infolog, critlog, funclog which just called my generic text() callable. BTW I say callable because I tried text as a function and as a subclass of object. But then turning on and off the different logs started adding a bunch of “log-managing-lines-of-code” to my source. If I had added more log functions there would have been even more mess.

So then I make my own logger class with IsActive and some other internal record keeping attributes. I put an instance each logger I want on in its own loggers namespace (because I hate globals) that I instintate either before the wx.App() object or in it.

So now in methods I want to debug with “prints” or “logs” I do:

def somemethod(self, stuff…):

mthlog = loggers.MyLoggers(‘somemthod’, IsActive=True)

… do stuff…

mthlog(on, indent=4, “hey does” 'this ’ ‘%s’ % ‘yes’, quoteit(somestuff), printsdicttoo, and=‘this as well’)

mthlog(off, 4, “don’t need ‘indent=’”)

del mthlog

return return_val

In that example when the logger is instinated if prints “method bla bla enter” on del it prints “method bla bla exit” with appropiate indent.

That’s just some stuff I played around with. I haven’t seen the right way to log lots of debug stuff. So hearing other’s ways might help me.

I've been doing about the same thing, and from what I can tell the @
decorators can be used, there was a post a few days back about it. And
in Building Skills in Python on the python.org site(i think that's
where i got it) you can find a trace function to use. If I'm getting
the gist of it right.