[Tutor] module.class.method in logging.debug
bkjones at gmail.com
Mon Mar 15 18:26:27 CET 2010
I have some code that is a plugin for a larger app, and I'd like to be able
to properly log issues that arise in the plugin code. I may not be
maintaining this code forever, and I'd like the logging to work even if it's
refactored later and code moved around, method names change, etc. So I'd
like my logging to include a string identifying (programatically) the
"module.class.method" where things went afoul.
I tried a couple of things I could think of, and successfully got the module
and class without issue, but the one missing piece was the method name. I
imagine a method can introspect and get its own name, but I haven't been
able to find the incantation to make it work. I saw the documentation on the
data model here: http://docs.python.org/reference/datamodel.html but I
think the use of things like im_func or __func__ assume that you're
referencing those as an attribute of a method object. I'm just not sure how
that's done from inside the method itself. Clues hereby solicited.
Brian K. Jones
Python Magazine http://www.pythonmagazine.com
My Blog http://www.protocolostomy.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor