nickponline
nickponline

Reputation: 25914

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

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?

Upvotes: 2

Views: 1256

Answers (1)

Ben Darnell
Ben Darnell

Reputation: 22134

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.

Upvotes: 2

Related Questions