I have a tornado server that automatically outputs logs whenever an URL is reached for example:
Jun 10 18:33:49 localhost server: INFO 200 GET /api/v1/profile (108.162.245.195) 0.69ms
I would like to change the format of these messages to include some more information like the username for example:
Jun 10 18:33:49 localhost server: INFO 200 GET /api/v1/profile (108.162.245.195) 0.69ms ([email protected])
How can I add this functionality?
This message comes from
Application.log_request
, so to change it you can subclassApplication
and define your ownlog_request
method. (it's also possible to passlog_function
as a keyword argument to the Application constructor if you prefer not to subclass).The
RequestHandler
is passed tolog_request
so you can accesshandler.current_user
or other methods to collect additional information to log.