logging: local functions ==> loss of lineno
__peter__ at web.de
Fri Mar 19 08:56:46 CET 2010
Hellmut Weber wrote:
> your hack is exactly what I was looking for.
> It permits to configure my logging messages as I want, e.g. using
> different colors for different classes of messages.
> I do not yet understand all details WHY it is working but suppose some
> study of the logging module will help me to understand.
Have a look at Logger.findCaller() in logging/__init__.py. To find the
calling function it does something like
for frame in walk_callstack():
if filename_of(frame) == _srcfile:
The _srcfile is normally logging/__init__.py, and it is skipped because a
user typically is interested only in what happens outside the logging
My hack under the hood changes
filename_of(frame) == _srcfile
from a string comparison to a
filename_of(frame) in set_of_files
containment test (see SrcFile.__eq__() posted above).
More information about the Python-list