Search code examples
pythonloggingtornado

Tornado: get log_message of HTTPError for logging during on_finish of request handlers?


I want to do some custom logging with Tornado.

When I throw a tornado.web.HTTPError with an error message, is there a way for me to retrieve the message for my request handler's on_finish() method? If not, how can I log it?

Thanks in advance.


Solution

  • It is possible to override RequestHandler's write_error method:

    RequestHandler.write_error(status_code, **kwargs)
    

    You can process the exception there: log it or show custom page. The details of exception are kept in kwargs["exc_info"].