classification
Title: logging.error('...', exc_info=True) should display upper frames, too
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: guettli, piotr.dobrogost, r.david.murray, stutzbach, vinay.sajip
Priority: normal Keywords:

Created on 2010-07-30 11:25 by guettli, last changed 2015-06-09 06:09 by piotr.dobrogost. This issue is now closed.

Messages (6)
msg112063 - (view) Author: Thomas Guettler (guettli) Date: 2010-07-30 11:25
logging.error('...', exc_info=True) only displays the
frames downward. But I often need the upper frames, to debug a problem.

This example shows, that you don't see the "upper" frame in the stactrace. But that's information is important.

<pre>
import logging

def foo():
    try:
        raise Exception()
    except Exception, exc:
        logging.error('Exception occured: %s' % exc, exc_info=True)

def upper():
    foo()
upper()
</pre>

<pre>
===> python tmp/t.py
ERROR:root:Exception occured: 
Traceback (most recent call last):
  File "tmp/t.py", line 6, in foo
    raise Exception()
Exception
</pre>
msg112064 - (view) Author: Thomas Guettler (guettli) Date: 2010-07-30 11:27
Related: #1553375
msg112067 - (view) Author: Thomas Guettler (guettli) Date: 2010-07-30 11:34
I tested it only on python 2.6. Can someone please look at more reset versions?
msg112955 - (view) Author: Thomas Guettler (guettli) Date: 2010-08-05 08:08
Until exc_info=True prints the current stack, I use this pattern:

import traceback

logging.error(u's...\nStack: %s' % (
    ''.join(traceback.format_stack())), exc_info=True)
msg114973 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2010-08-26 13:31
This also happens on later versions. Since 2.x is essentially frozen, this feature request can't be implemented in 2.x, so recategorising as a Python 3.2 issue.

Here, a change in logging will either duplicate code in traceback.py or print the upper frames above the "Traceback (most recent call last):" line, which is not ideal.

The best way to implement in logging would be to wait for the implementation of the patch in #1553375, following which a change could be made in Formatter.formatException to invoke traceback.print_exception with the "fullstack" keyword parameter.
msg130281 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2011-03-07 18:46
I'll close this, assuming that the stack_info keyword parameter added to logging calls in 3.2 will be sufficient.

I also removed the dependency on 1553375, which would prevent closure.
History
Date User Action Args
2015-06-09 06:09:15piotr.dobrogostsetnosy: + piotr.dobrogost
2011-03-07 18:46:34vinay.sajipsetstatus: open -> closed
nosy: vinay.sajip, guettli, stutzbach, r.david.murray
messages: + msg130281

dependencies: - Add traceback.print_full_exception()
resolution: fixed
2011-03-04 17:41:47stutzbachsetnosy: + stutzbach
dependencies: + Add traceback.print_full_exception()

versions: + Python 3.3, - Python 3.2
2010-08-26 13:40:33r.david.murraysetnosy: + r.david.murray
2010-08-26 13:32:00vinay.sajipsettype: enhancement
messages: + msg114973
versions: + Python 3.2, - Python 2.6
2010-08-22 18:52:49vinay.sajipsetassignee: vinay.sajip

nosy: + vinay.sajip
2010-08-05 08:08:21guettlisetmessages: + msg112955
2010-07-30 11:34:06guettlisetmessages: + msg112067
2010-07-30 11:27:20guettlisetmessages: + msg112064
2010-07-30 11:25:47guettlicreate