Add source code context information to debug logs
authorJohn Dennis <jdennis@redhat.com>
Mon, 12 Jan 2015 15:47:37 +0000 (10:47 -0500)
committerSimo Sorce <simo@redhat.com>
Mon, 26 Jan 2015 19:01:03 +0000 (14:01 -0500)
commit74194d5d36cfc1be67e92924585731e9b3894605
tree8f1f6c953615957d7af9954b9a5f6d56c6eb2045
parente85f190d8e081fbbfeadca24781266d1c3e1bba1
Add source code context information to debug logs

The log.debug() function helpfully adds the name of the function
invoking it but in a complicated software package there are many
functions/methods which share the same name. Thus a debug message
like this:

DEBUG(__init__): xxx

does not give you much context, there are probably hundreds of
__init__ methods. It would help to qualify the method name which it's
class name, that gives a lot more context when reading the
log. Sometimes it's also helpful to know the file and line number.

This patch adds the class name to the function and included the
filename and line number as well. The file path is trimmed to the last
3 components, sufficient to give context but not too verbose. Now the
debug message might look like this instead:

DEBUG(ipsilon/providers/common.py:129 LoadProviders.__init__()): xxx

Also included is a config option 'stacktrace_on_error' which will
include a stacktrace when the log.error function is called. It can be
very useful to see a stacktrace when logging an error, it defaults to
off.

Signed-off-by: John Dennis <jdennis@redhat.com>
Reviewed-by: Simo Sorce <simo@redhat.com>
ipsilon/util/log.py