Logging not working as expected within add_exception_handler() #30
-
|
I'm using a small test program (below) in order to try to integrate fastapi-problem exceptions with a logger. In this example, the logger is configured to output to stdout. You can see in the outputs (also below) that the 404 Not Found exception is handled and the correct response is created, though there is no output to stdout... Am I misunderstanding the role or usage of the "logger" variable in add_exception_handler() ? It seems they aren't being handled by the logger I specified. Code: Curl requests: Output: I am also expecting something like |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
The logger is used when a 5xx error occurs to capture the stacktrace. 4xx errors aren't logged as they are caused and fixed by user behaviour. There is (usually) no need to log the cause or a 404 etc as it is known why that has happened, the route called doesn't exist etc. As 5XXs are often unexpected being able to trace the root cause is more viable. |
Beta Was this translation helpful? Give feedback.
-
|
Side note, detail for a Problem is provided when raised, specifying it on the class will be ignored/overridden, which is why you are not seeing it in the response. |
Beta Was this translation helpful? Give feedback.
The logger is used when a 5xx error occurs to capture the stacktrace. 4xx errors aren't logged as they are caused and fixed by user behaviour. There is (usually) no need to log the cause or a 404 etc as it is known why that has happened, the route called doesn't exist etc.
As 5XXs are often unexpected being able to trace the root cause is more viable.