3

我希望将每个请求的日志组合在一起,以便与另一个请求的日志区分开来,例如

**********************

Started GET "/" for 67.205.67.76 at 2013-09-15 00:05:15 -0700
Processing by RootController#index as HTML
Rendered root/_index.html.erb within layouts/application (7.0ms)
Rendered layouts/_fonts_hack.html.erb (0.0ms)
Rendered layouts/_ie_version_vars.html.erb (0.0ms)
Rendered topbars/_logged_out_topbar.html.erb (2.0ms)
Rendered layouts/_old_browser_warnings.html.erb (0.0ms)
Completed 200 OK in 27ms (Views: 26.0ms | ActiveRecord: 0.0ms)

**********************

Started GET "/" for 67.205.67.76 at 2013-09-15 00:05:15 -0700
Processing by RootController#index as HTML
Rendered root/_index.html.erb within layouts/application (7.0ms)
Rendered layouts/_fonts_hack.html.erb (0.0ms)
Rendered layouts/_ie_version_vars.html.erb (0.0ms)
Rendered topbars/_logged_out_topbar.html.erb (2.0ms)
Rendered layouts/_old_browser_warnings.html.erb (0.0ms)
Completed 200 OK in 27ms (Views: 26.0ms | ActiveRecord: 0.0ms)

***********************

这样的事情可能吗?有时在我的日志中,目前很难直观地看到一个请求从哪里开始,另一个请求在哪里结束,有时来自不同请求的日志会散布在其中。

4

2 回答 2

2

更好的选择是使用请求 uuid

config.log_tags = [:uuid]
于 2021-05-05T14:07:36.547 回答
1

据我所知,这似乎不像,但下一个最好的事情是:将 Pid 和 Thread object_id 标签添加到每个日志,然后在请求开始时搜索并突出显示特定标签,然后所有突出显示的行将成为您要求的人。

config.log_tags = [ lambda {|r| "#{Process.pid}##{Thread.current.object_id}" } ]
于 2013-09-21T08:16:23.290 回答