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 subclassApplicationand define your ownlog_requestmethod. (it's also possible to passlog_functionas a keyword argument to the Application constructor if you prefer not to subclass).The
RequestHandleris passed tolog_requestso you can accesshandler.current_useror other methods to collect additional information to log.