python-devtools icon indicating copy to clipboard operation
python-devtools copied to clipboard

Option to include stack trace in `debug()` output?

Open kalekundert opened this issue 2 years ago • 2 comments

Today I was trying to debug an issue where a function of mine was unexpectedly being called from two places. I was using debug() within the function, but it only reports the file/line number/function that it was directly invoked from, which in this case I knew. I wanted to know where this function was being called from, so I looked for a way to get a full stack trace by doing something like debug(trace=True). As far as I can tell, this option doesn't exist yet.

Is there interest in adding such an option? If so, I could probably try to make a PR in the near-ish future.

kalekundert avatar Jun 07 '22 14:06 kalekundert

Yes definitely, I often want this, just haven't had time to implement it.

I guess:

  • trace_ kwarg for debug to include the trace
  • debug.trace() to just print the traceback to the current position

Both should be highlighted I guess if pygments is installed, I seem to remember that pygments has a custom highlighting language for python tracebacks, but I might be wrong.

samuelcolvin avatar Jun 07 '22 14:06 samuelcolvin

That sounds like a good API to me. No promises that I'll get around to this super-soon, but good to know that a PR is welcome.

kalekundert avatar Jun 07 '22 15:06 kalekundert