logging.Logger 的 debug 怎么 traceback
时间: 2023-12-04 07:06:52 浏览: 72
`logging.Logger` 的 `debug` 方法默认不会输出 traceback,但是可以通过设置 `exc_info` 参数为 `True` 来输出 traceback。
示例代码:
```python
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
try:
1 / 0
except ZeroDivisionError:
logger.debug('Error occurred', exc_info=True)
```
输出结果:
```
DEBUG:__main__:Error occurred
Traceback (most recent call last):
File "test.py", line 9, in <module>
1 / 0
ZeroDivisionError: division by zero
```
阅读全文