How to log specific request details to rails server logs

前端 未结 2 597
自闭症患者
自闭症患者 2021-02-07 20:13

I typically don\'t like to ask directly how to do something without much understanding of what\'s going on, but I\'m fairly new to rails and I\'m having a hard time accomplishin

2条回答
  •  别那么骄傲
    2021-02-07 20:36

    I know this is an old question, but for future people that stumble upon this, I believe the preferred approach in Rails 3.2+ would be to use ActiveSupport::TaggedLogging. The blog post introducing this is here

    And a quick example that adds the subdomain, a UUID per request, and the user agent to each log message. You can pop this in your environment initialization file.

    config.log_tags = [ :subdomain, :uuid, lambda { |request| request.user_agent } ]
    

提交回复
热议问题