Vinay Sajip <vinay_sa...@yahoo.co.uk> added the comment:

A number of points:

1. exc_text is not just an implementation detail - it's in the docs. Thus, 
removing the cache altogether would be backwards-incompatible.

2. The exc_text value is the only simple way of propagating the exception 
information across the wire, which is a common use case (e.g SocketHandler).

3. This is not a "behavior" issue, as the behaviour is by design and documented.

4. What's wrong with the following approach?

class NoStackTraceFormatter(logging.Formatter):
    def formatException(self, exc_info):  # Don't emit the stack trace
        return '\n'.join(traceback.format_exception_only(exc_info[0], 
exc_info[1])) # type and value only

    def format(self, record):
        saved_exc_text = record.exc_text # optional
        record.exc_text = None
        result = super(NoStackTraceFormatter, self).format(record)
        record.exc_text = saved_exc_text # or None, if you want
        return result

You can either save and restore the previous exc_text value, or set it to None 
after the parent class operation - this will cause it to be always recomputed 
by the next handler. This way, a handler which needs abbreviated information 
always gets it, but other handlers append the full stack trace.

I'm closing this as I believe my suggestion shows a way of subclassing and 
overriding which works. You can re-open if you think I've missed something.

----------
nosy: +vinay.sajip
resolution:  -> invalid
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue14024>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to