Tuesday, August 13, 2013

Adding Process ID and timestamps to the Rails Logger

For the last few days, I've been trying to debug a race condition between several Delayed::Job workers.  After looking at log files for many hours, it became very frustrating to not know which one of my 3 workers was writing which statement.  I finally found this post which almost did what I wanted.

To add process ids and timestamps to your Rails logs, you can add this as a Rails initializer (config/initializers/log_formatting.rb for instance) and restart your application / workers:



config/initializers/log_formatting.rb:

Before:

Log formatting before adding process ids and timestamps

After:


Log format after adding process IDs and Timestamps

1 comment: