案例是这样的: 一个 Rails3 应用,部署在 Passenger 上,现在需要添加请求日志分析功能,于是我们在日志输出格式里添加了当前进程号。由于进程可能重复使用,我们希望加入 RequestID, 到每一行日志中,请问有做过的吗?
原始日志:Rendered users/login.html.erb within layouts/application (38.8ms) 添加进程号:[4022] Rendered users/login.html.erb within layouts/application (38.8ms) 期望: [4022][xxxxx(request_id)] Rendered users/login.html.erb within layouts/application (38.8ms)
request_id:请参考 ActionDispatch/RequestId
谢谢 @hz_qiuyuanxin , @Rei 方案:
# config/environments/development.rb
# process_id, request_id
config.log_tags = [lambda{|req| $$}, :uuid]