Can you change the log output format for a tornado app?

1.2k views Asked by At

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?

1

There are 1 answers

2
Ben Darnell On BEST ANSWER

This message comes from Application.log_request, so to change it you can subclass Application and define your own log_request method. (it's also possible to pass log_function as a keyword argument to the Application constructor if you prefer not to subclass).

The RequestHandler is passed to log_request so you can access handler.current_user or other methods to collect additional information to log.