Skip to content

Commit

Permalink
app.debug(): More verbose debugging information
Browse files Browse the repository at this point in the history
  • Loading branch information
Lestropie committed Jun 19, 2017
1 parent 3fe0144 commit 101f73b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/mrtrix3/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,19 @@ def debug(text):
if _verbosity <= 2: return
stack = inspect.stack()[1]
try:
filename = stack.filename
fname = stack.function
except: # Prior to Version 3.5
filename = stack[1]
fname = stack[3]
sys.stderr.write(os.path.basename(sys.argv[0]) + ': ' + colourDebug + '[DEBUG] ' + fname + '(): ' + text + colourClear + '\n')
funcname = fname + '()'
modulename = inspect.getmodulename(filename)
if modulename:
funcname = modulename + '.' + funcname
# If debug() has been called from within some external function (e.g. a library function), it's often to report on the outcome of that function.
# In this instance, find the location where that function itself was called from, rather than where debug() was called from.
caller = inspect.getframeinfo(inspect.stack()[min(2,len(inspect.stack()))][0])
sys.stderr.write(os.path.basename(sys.argv[0]) + ': ' + colourDebug + '[DEBUG] ' + funcname + ' (from ' + os.path.basename(caller.filename) + ':' + str(caller.lineno) + '): ' + text + colourClear + '\n')

def error(text):
import os, sys
Expand Down

0 comments on commit 101f73b

Please sign in to comment.