Archive for December, 2007

Rails logger rotation

The mongrel rails log file grows rather quickly, even in production mode since every request is logged. Log rotating becomes a basic necessity. After googling there appears to be 2 standard ways of rotating logs: use the built in rails logger parameters or use an external rotator such as logrotate. Many have also expressed problems with clustering using the built-in logger rotation.

I couldn’t find a ready Windows implementation of logrotate (I was avoiding having to build it myself) and therefore I settled for the built-in rails logger. Clustering wasn’t really an option for me due to some internal reasons. I set up the test rotation for 20 files having 10kb each, and I thought I was done when I saw backup log files of 10kb created. But when it hit the 20files, it didn’t erase the last file. Instead, it continued to increment the latest file beyond its 10kb limit!

Well, that wasn’t what I thought about rotation. After various searches in vain I took a plunge into the source pool. There, I found the implementation performs a rename of the previous log files to “shift” them. A-ha. I did a quick test with the rename function using Ruby and JRuby and found that JRuby doesn’t do rename the same as Ruby. It was supposed to overwrite it but it didn’t, nor did it throw an error.

I did a quick patch to delete the file to be rename if it exist, so that it would rename successfully. Following that, I filed a JRuby bug. Not sure if it’s really a bug, but well. Let them decide.

Comments