-
-
Notifications
You must be signed in to change notification settings - Fork 944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log all exceptions #1942
Comments
Hi, If you just want to log them and otherwise let the default error handler create the response, I think at the moment the best options may be to override the Lines 1004 to 1038 in e255bff
|
Overriding a private method of the Is exc_info somehow propagated with the response, such that I could do this in Middleware? (otherwise I loose the traceback info, even if I could filter by status code) |
I agree that's not optional. What is your use case? Do you just wanted to log the exception and retain the default handlers? |
Yes, exactly. I just want to log the exceptions, I don't want to do anything else with them. As far as I can tell, Falcon does not log them. Modifying the server's (in my case Gunicorn) loggers is not an option because:
|
Hi @adriangb ! OTOH, do you really need to pass the exception object? I think Python's I've hacked together the following prototype using the reraising approach: import logging
import falcon
logging.basicConfig(format='%(asctime)-15s [%(levelname)s] %(message)s')
def handle_uncaught_exception(req, resp, ex, params):
logging.exception('Unhandled error')
raise falcon.HTTPInternalServerError(title='App error')
def handle_http_error(req, resp, ex, params):
logging.exception('HTTP error')
raise ex
class FaultyResource:
def on_get(self, req, resp):
0 / 0
app = falcon.App()
app.add_error_handler(falcon.HTTPError, handle_http_error)
app.add_error_handler(Exception, handle_uncaught_exception)
app.add_route('/fault', FaultyResource()) |
Hey @vytas7, thanks for the quick response!
Yes, but only if you are within a
That's very similar to what I ended up with. Thank you for confirming that this is the best approach, I'll move forward with it. |
@vytas7 is there any reason not to add a |
I think we already have something like that for the generic Exception handler. As to other errors like 404, it might be a performance issue / unexpected bulk spam if the said path is hit often. That said, I think we should reopen this issue, at least in terms of documentation/recipes. It's not an unreasonable request to be able to log all errors. |
Yes, the default generic error logger does log to |
Related to this, over in open-telemetry/opentelemetry-python-contrib#644 we realized that
Option (2) I think also resolves this issue, which is why I think it's relevant. |
See also snapADDY/elastic-apm-falcon#1 by @benedikt-budig and @severinsimmler, which could also make use of this functionality if added in some form. |
I'd like to log all exceptions, including falcon exceptions.
I made a catch-all handler:
But the way handler resolution is set up, the most specific Exception subclass is chosen. Which means that in order to log
falcon.HTTPError
I have to do this:Which works, but is a bit janky. Is there any way to log
falcon.HTTPError
exceptions without overriding the default handler?Thanks
The text was updated successfully, but these errors were encountered: