简体   繁体   English

您可以更改龙卷风应用程序的日志输出格式吗?

[英]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: 我有一个龙卷风服务器,只要到达URL,它就会自动输出日志,例如:

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. 该消息来自Application.log_request ,因此要对其进行更改,您可以将Application子类化并定义您自己的log_request方法。 (it's also possible to pass log_function as a keyword argument to the Application constructor if you prefer not to subclass). (如果不想使用子类,也可以将log_function作为关键字参数传递给Application构造函数)。

The RequestHandler is passed to log_request so you can access handler.current_user or other methods to collect additional information to log. RequestHandler传递给log_request这样你就可以访问handler.current_user或其它方法来收集更多的信息登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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