logging.Logger 的 debug 怎么 traceback
时间: 2023-12-04 19:06:52 浏览: 78
`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
```
相关问题
python logger.exception(e)
This code snippet is using the Python logger module to log an exception that occurred in the program.
The "logger" object should be created beforehand using the `logging.getLogger()` method.
The `exception()` method of the logger module is used to log an exception message with the level `ERROR`. It takes one argument, which is the exception object that was raised in the program.
By calling `logger.exception(e)`, the logger will capture and log the exception message along with the full traceback. This makes it easier to identify and debug errors in the program.
阅读全文
相关推荐

















