Introduction
Today, I had to find a way to make my production Rails application log into different log files per process. I have the application deployed using Phusion Passenger as an Apache 2 module. The reason I decided to do that was the fact that I wanted to analyze the logs with Request Log Analyzer tool. This tool requires the log files to be separate so that they do not interleave the log entries of different requests.
Blog Sponsor
This post is sponsored by Fraudpointer.
References
In order to solve that I was helped by what I found about the similar problem solved for Unicorn processes here:
A blog about how one can have different log file per Unicorn worker
Then, I had to google about how I could hook to after fork events on Phusion Passenger. There was a very good question here and its answer here. The answer directed me also on Phusion Passenger documentation for hooking on spawning events.
Implementation
I have created an initializer with the following content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
Closing
This has been implemented for a Rails 3.2 and a Rails 4.2 application.
Any feedback from you would be much appreciated.