Writing traceback

Robert Brewer fumanchu at amor.org
Mon Aug 16 00:26:29 EDT 2004


Ehab Teima wrote:
> I have built a server application. It's multithreaded, and everything
> works fine so far. I have only one issue with catching exceptions
> after I read the documentation but I can't find any problems yet. I'm
> catching all errors throughout the code into a function and I write
> the traceback to the server log as well as the screen. That's all. I
> need not to save it or anything else. The documentation said the
> function (in this example catchError) should not handle exceptions
> itself. How would I get around this issue given that writing to the
> server log must not stop the server? In other words, the function
> itself must handle and ignore any exceptions raised by itself. i.e. I
> want to make sure that failing to write to the server log is ignored.

I would suggest you use the "logging" module instead of rolling your
own. Once you've set up the handler, logging complete, annotated
exceptions is as simple as "logger.exception(msg)". Try
logging.handlers.RotatingFileHandler in particular.

If you inspect that module's code, you might notice that even it handles
exceptions (see logging.FileHandler.emit()).


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org



More information about the Python-list mailing list