Closed qq745639151 closed 2 weeks ago
This is the output when diagnose=True
2024-06-15 19:12:27.677 | ERROR | __main__:nested:15 - What?!
Traceback (most recent call last):
File "F:\WorkSpace\PycharmProjects\fastapi_learning\async_log.py", line 17, in <module>
nested(0)
└ <function nested at 0x000001D782E3D090>
> File "F:\WorkSpace\PycharmProjects\fastapi_learning\async_log.py", line 13, in nested
func(5, c)
│ └ 0
└ <function func at 0x000001D780773E20>
File "F:\WorkSpace\PycharmProjects\fastapi_learning\async_log.py", line 9, in func
return a / b
│ └ 0
└ 5
ZeroDivisionError: division by zero
and This is the output when diagnose=False
2024-06-15 19:15:01.122 | ERROR | __main__:nested:15 - What?!
Traceback (most recent call last):
File "F:\WorkSpace\PycharmProjects\fastapi_learning\async_log.py", line 17, in <module>
nested(0)
└ <function nested at 0x000002B83785D090>
> File "F:\WorkSpace\PycharmProjects\fastapi_learning\async_log.py", line 13, in nested
func(5, c)
│ └ 0
└ <function func at 0x000002B834E03E20>
File "F:\WorkSpace\PycharmProjects\fastapi_learning\async_log.py", line 9, in func
return a / b
│ └ 0
└ 5
ZeroDivisionError: division by zero
The diagnose
formatting should work regardless of the logging output.
Are you sure you did remove the default handler? Maybe call logger.remove()
first. Also, be aware that if you run multiple FastAPI workers, your main file will be executed multiple times, which can disrupt the configuration of your logger.
Thanks for your answer. I have tried and solved the question. Thanks again
I tried the example, but I set the diagnose=False
but the output is the same as in the case of diagnose=True.