Re: Repeated output when logging exceptions
Vinay Sajip wrote: I'm not sure why you need all the code you've posted. The logging package allows you to add tracebacks to your logs by using the exception() method, which logs an ERROR with a traceback and is specifically intended for use from within exception handlers. You can also use the exc_info=True parameter with any logging method... Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Repeated output when logging exceptions
John Gordon wrote: If I didn't do all that in a class, where would I do it? I find the configureLoggers method of ZConfig most convenient for this: http://pypi.python.org/pypi/ZConfig cheers, Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Repeated output when logging exceptions
On Sep 28, 9:38 pm, John Gordon gor...@panix.com wrote: If I didn't do all that in a class, where would I do it? You could, for example, use the basicConfig() function to do it all for you. import logging logging.basicConfig(filename='/path/to/my/log',level=logging.DEBUG) logging.debug('This message should go to the log file') Here's the documentation link for simple examples: http://docs.python.org/library/logging.html#simple-examples Here's the link for basicConfig: http://docs.python.org/library/logging.html#logging.basicConfig Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: Repeated output when logging exceptions
In 6bce12c3-f2d9-450c-89ee-afa4f21d5...@h30g2000vbr.googlegroups.com Vinay Sajip vinay_sa...@yahoo.co.uk writes: The logging package allows you to add tracebacks to your logs by using the exception() method, which logs an ERROR with a traceback and is specifically intended for use from within exception handlers. All that stuff with temporary files seems completely unnecessary, even with Python 2.3. I didn't know about the exception() method. Thanks! In general, avoid adding handlers more than once - which you are almost guaranteed to not avoid if you do this kind of processing in a constructor. If you write your applications without using the exceptionLogger class (not really needed, since logging exceptions with tracebacks is part and parcel of the logging package's functionality since its introduction with Python 2.3), what functionality do you lose? I'm trying to encapsulate all the setup work that must be done before any actual logging occurs: setting the debugging level, choosing the output filename, declaring a format string, adding the handler, etc. If I didn't do all that in a class, where would I do it? -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
Re: Repeated output when logging exceptions
On Mon, Sep 28, 2009 at 4:38 PM, John Gordon gor...@panix.com wrote: In 6bce12c3-f2d9-450c-89ee-afa4f21d5...@h30g2000vbr.googlegroups.com Vinay Sajip vinay_sa...@yahoo.co.uk writes: The logging package allows you to add tracebacks to your logs by using the exception() method, which logs an ERROR with a traceback and is specifically intended for use from within exception handlers. All that stuff with temporary files seems completely unnecessary, even with Python 2.3. I didn't know about the exception() method. Thanks! In general, avoid adding handlers more than once - which you are almost guaranteed to not avoid if you do this kind of processing in a constructor. If you write your applications without using the exceptionLogger class (not really needed, since logging exceptions with tracebacks is part and parcel of the logging package's functionality since its introduction with Python 2.3), what functionality do you lose? I'm trying to encapsulate all the setup work that must be done before any actual logging occurs: setting the debugging level, choosing the output filename, declaring a format string, adding the handler, etc. If I didn't do all that in a class, where would I do it? Put it in a module. :] -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
Re: Repeated output when logging exceptions
On Sep 24, 8:43 pm, John Gordon gor...@panix.com wrote: Why is this happening? I suspect it's because I'm declaring two instances of the exceptionLogger class, which ends up calling logger.addHandler() twice. Is that right? Yes, that's why you get duplicated lines in the log. What would be a better way to handle this? I'm not sure why you need all the code you've posted. The logging package allows you to add tracebacks to your logs by using the exception() method, which logs an ERROR with a traceback and is specifically intended for use from within exception handlers. All that stuff with temporary files seems completely unnecessary, even with Python 2.3. In general, avoid adding handlers more than once - which you are almost guaranteed to not avoid if you do this kind of processing in a constructor. If you write your applications without using the exceptionLogger class (not really needed, since logging exceptions with tracebacks is part and parcel of the logging package's functionality since its introduction with Python 2.3), what functionality do you lose? Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list