简体   繁体   中英

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 (nick@hamburger.com)

How can I add this functionality?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM