Add process information to Rails logger

logging, ruby-on-rails-3

Solution

It looks like there are a few options out there for this:

- Subclass Buffered logger and use that instead: https://gist.github.com/krutten/1091611 (from http://help.papertrailapp.com/discussions/suggestions/18-include-pids-in-rails-productionlog)

- Create your own middleware that makes the pid available and use it with config.log_tags: http://www.peterboling.com/2012/4/5/rails-3-2-custom-logging

- Do this: `config.log_tags = [:subdomain, :uuid, :remote_ip, Proc.new { "PID-%.5d" % $$ }]` (which the previous link says is slow)

- Or this: `config.log_tags = [Proc.new { "PID: %.5d" % Process.pid }]`

- Log the request uuid instead

Here is a related SO article: - Rails 3.2.2 log files unordered, requests intertwined

The best bet to me seems to be to use :uuid instead. It conveys the same information to let you distinguish between requests when you have multiple processes logging to the same file.

Problem

I currently have a Rails application that has multiple processes: the web serving processes and the background workers, that are triggered by Redis. Problem is sometimes is hard to check the log files and determine where a given behavior happened - was it on the Web portion or on the Resque workers? Is there a way to include the process name or even process id or something that allows me to differentiate each log entry by process?

Original source

Related problems