logging: local functions ==> loss of lineno

Vinay Sajip vinay_sajip at yahoo.co.uk
Tue Mar 23 04:10:36 EDT 2010


On Mar 20, 8:36 am, Peter Otten <__pete... at web.de> wrote:
> Jean-Michel Pichavant wrote:
> > You are still accessing the private attribute of the  modulelogging.
>
> Just reading it is a significantly more conservative approach than setting
> it to an object with an unusual notion of equality ;)
>
> > My previous remark was misleading, in fact there's nothing you can do
> > about it.
>
> How about replacinglogging._srcfile with fixname(logging.__file__)?
>
> > _srcfile is not meant to be used elsewhere than in theloggingmodule
> > itself.
> > However, I don't wanna sound like I'm rejecting this solution, 1st the
> > OP is satisified with it and since this solution is working, it is still
> > more helpful than anyone noticing that you've accessed a private
> > attribute (some will successfully argue that python allows to do so).
>
> Yeah, I had hoped that I could get away without drawing the "consenting
> adults" wildcard...
>
> > At the very begining of this thread I've provided a complete different
> > approach, instead of using the builtin 'filename' and 'lineno' field of
> > thelogging, use custom fileds with the extra parameter.
>
> > It has also some drawbacks but could be a possible alternative.
>
> Having two filename/lineno sets ist likely to confuse.
>
> Peter

Guys,

Sorry I'm a little late to this discussion. I could add a _findCaller
function to the module (not part of the public API, but replaceable by
someone who really needs to) which does the heavy lifting, and
Logger.findCaller just calls it. Then those who need to can implement
their own strategy, without needing to jump through hoops. Does that
approach sound helpful?

Regards,

Vinay Sajip



More information about the Python-list mailing list