[Python-Dev] Re: PEP 282 comments (original) (raw)

Vinay Sajip vinay_sajip@red-dove.com
Mon, 25 Mar 2002 23:28:22 -0000


[Jim Fulton]

We have a need to make it easy to include error traceback in logs regardless of the level. I believe we have two possible mechanisms now: either (a) define a specific method which always includes tracebacks, and pass the level as a parameter: def exception(self, level, msg, *args): # log 'msg % args' with traceback at specified level

(b) use a keyword parameter on all of debug(), info(), warn(), error() and fatal(), all of which will have a common signature, for example

def debug(self, msg, *args, **kwargs) # log 'msg % args' at DEBUG level, include traceback if kwargs ["exc_info"] evaluates to true.

I'm equally comfortable with either approach. Though I share your reservations about kwargs, I'm persuaded by Kevin Butler's argument that the kwargs way allows greater extensibility. But either way will allow Zope logging the flexibility that Jeremy advocated.

D. Provide an exception formatter that delays formatting until a message is logged. I don't like this so much because I'd prefer that the decision about whether to show a tracebeck be a policy of the back end.

Formatting of the arguments is delayed for as long as possible after logging. A caller can check that the logger would actually record an event before bothering to compute the arguments for the message.

if logger.isEnabledFor(logging.WARN):

compute arguments arg1, arg2 etc. (could be expensive)

logger.warn(msg, arg1, arg2)

Regards

Vinay Sajip