Discussion:
Logging Errors?
Waylan Limberg
2014-10-10 19:51:36 UTC
Permalink
I'm trying to log errors to a file. Ideally, each log entry should include
the request info, the returned error code, and the Traceback.

I did find this [thread][1] which pointed to this [gist][2] which
demonstrates how to use the `@hooks` decorator and WsgiLog to implement
logging. .

At the very least, I was hoping to do something like this:

@app.hook('after_request')
def log_error():
if response.status_code >= 500:
# get latest traceback and log error...

Unfortunately, regardless of what is returned by Bottle,
`response.status_code` is always `200` within the hook so that doesn't
work. Is the hook being run to soon, or should I be looking elsewhere for
indication of an error? Perhaps in `request.environ`?

While it is not very well documented, it appears that WsgiLog has its own
Exception catching mechanism, but that would only work if Bottle allows the
errors to bubble up. But is is not clear to me how to do that or if it is
even possible.

I can catch the errors myself in each route and log them, but I'd rather
have all logging configured for the entire site in one place.

Any suggestions?

[1]: https://groups.google.com/forum/#!searchin/bottlepy/log/bottlepy/yjPJ0ANo9hE/5pEhwP2OqXcJ
[2]: https://gist.github.com/iurisilvio/3654741
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Marcel Hellkamp
2014-10-11 14:34:21 UTC
Permalink
Post by Waylan Limberg
I'm trying to log errors to a file. Ideally, each log entry should
include the request info, the returned error code, and the Traceback.
[...]
Unfortunately, regardless of what is returned by Bottle,
`response.status_code` is always `200` within the hook so that
doesn't work. Is the hook being run to soon, or should I be looking
elsewhere for indication of an error? Perhaps in `request.environ`?
The after_request hook is not called in some situations (which is not
desired but hard to fix without breaking stuff). I'd either install a
500 error handler (@app.error(500)) or use a middleware for detailed
logging.
Post by Waylan Limberg
While it is not very well documented, it appears that WsgiLog has its
own Exception catching mechanism, but that would only work if Bottle
allows the errors to bubble up. But is is not clear to me how to do
that or if it is even possible.
app.catchall = False

This way bottle won't catch any non-HTTPError exceptions.


--

Loading...