[Python-Dev] PEP282 and the warnings framework
Tue, 21 May 2002 12:58:15 +0200
Vinay Sajip wrote:
>>>I think a better design is to pass in a callable which constructs the
>>>LogRecord or a derived class thereof. This way, you can use a class, a
>>>function, a bound method which has access to other context, or whatever.
>>This will work in my version without a problem, because
>>a function is not an instance of LogRecord.
> True enough, though it's more by accident than design.
Ouch ;), you're right, I didn't think about other callables.
>>>logger.warn("Hello, %s", "world!", record=myRecordMaker)
>>So go one step further and allow:
>> logger.warn(myRecordMaker("Hello, %s", "world!"))
> It's more than just a step further. In my case, it's an optional
> In your case, everyone has to do it that way.
Not with something like this:
def log(self, lvl, msg, args, exc_info, eventtype=LogRecord):
if not isinstance(msg, LogRecord):
event = eventtype(msg, args)
with this solution you can still use a string for msg.
>>(I assume that MySpecialRecord is derived from LogRecord).
>>Either the LogRecord constructor should be responsible
>>for creating the timestamp and finding file/line info. etc.
>>or this could be done by the logger (via calling a method
>>on the LogRecord instance).
> Yes, I had the same idea, mentioned earlier in this post. Still
> it :-)
BTW, is there a public CVS repository for the logging module?