Hi mongrel-herders, I''m just wondering what fellow railsers use to rotate their logs in an orderly fashion? I''d like to do something lightweight, i.e. (1) rename the logfile (2, optional) create a new empty logfile and (3) send a signal to each mongrel in the cluster and have them understand it''s time to reopen their log file handles. This is what I do with apache and nginx and loads of other apps. Although the question is simple as stated, let me elaborate a little to avoid having the discussion going the wrong way (rein it in, as it were): 1. I''m really only concerned about production.log, since that is the big file. A solution that lets me rotate mongrel.log too is fine, but not necessary. 2. I know I can send a SIGUSR2 to each mongrel (or do a mongrel_cluster restart) to restart mongrel, but I''m running on a low-end machine which takes no less than 30 seconds to start rails, so I''d rather avoid the overhead. And even if it didn''t, I think most of us agree that there''s no real point in stopping out app even for a second just to reopen a file handle. 3. I realise that mongrel isn''t rails-bound, so it might not be mongrel''s responsibility to make rails switch log files. In that case, please point me in another direction and I''ll see what I find. 4. I see that I can send a SIGHUP to mongrel which might make it do the right thing, but the caveat "(Internal reload) that might not work so well." is all but encouraging. Seeing as I''ve come this far, perhaps I should take a step back and ask: what do fellow mongrel_railsers use for logging? Logger? Log4R? Something else entirely? And what made you decide on the solution you use? Hope you haven''t choked on my ramblings, and I look forward to your collective wisdom! /David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20061001/9230320f/attachment.html
You can do something like this in environment.rb config.logger Logger.new("#{RAILS_ROOT}/log/#{ENV[''RAILS_ENV'']}.log", 50, 4194304) Check the docs for Logger for more information. -carl On 10/1/06, David Vrensk <david at vrensk.com> wrote:> Hi mongrel-herders, > > I''m just wondering what fellow railsers use to rotate their logs in an > orderly fashion? I''d like to do something lightweight, i.e. (1) rename the > logfile (2, optional) create a new empty logfile and (3) send a signal to > each mongrel in the cluster and have them understand it''s time to reopen > their log file handles. This is what I do with apache and nginx and loads > of other apps. > > Although the question is simple as stated, let me elaborate a little to > avoid having the discussion going the wrong way (rein it in, as it were): > > 1. I''m really only concerned about production.log, since that is the big > file. A solution that lets me rotate mongrel.log too is fine, but not > necessary. > > 2. I know I can send a SIGUSR2 to each mongrel (or do a mongrel_cluster > restart) to restart mongrel, but I''m running on a low-end machine which > takes no less than 30 seconds to start rails, so I''d rather avoid the > overhead. And even if it didn''t, I think most of us agree that there''s no > real point in stopping out app even for a second just to reopen a file > handle. > > 3. I realise that mongrel isn''t rails-bound, so it might not be mongrel''s > responsibility to make rails switch log files. In that case, please point > me in another direction and I''ll see what I find. > > 4. I see that I can send a SIGHUP to mongrel which might make it do the > right thing, but the caveat "(Internal reload) that might not work so well." > is all but encouraging. > > Seeing as I''ve come this far, perhaps I should take a step back and ask: > what do fellow mongrel_railsers use for logging? Logger? Log4R? Something > else entirely? And what made you decide on the solution you use? > > Hope you haven''t choked on my ramblings, and I look forward to your > collective wisdom! > > /David > > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users > >
Carl Lerche wrote:> You can do something like this in environment.rb > > config.logger > Logger.new("#{RAILS_ROOT}/log/#{ENV[''RAILS_ENV'']}.log", 50, 4194304)Or use a custom script for well established logrotate. For once this is already used to rotate other logs in the system, and will work correctly unlike the above snippet prone to failure if multiple ruby processes try to rotate at the same time. -- Company - http://primalgrasp.com Thoughts - http://deezsombor.blogspot.com
On 10/9/06, Carl Lerche <carl.lerche at gmail.com> wrote:> > You can do something like this in environment.rb > > config.logger > Logger.new("#{RAILS_ROOT}/log/#{ENV[''RAILS_ENV'']}.log", 50, 4194304) > > Check the docs for Logger for more information.Hi Carl, I will definately investigate that. It seems simple enough, but at the same time it stirs the suspicion that all my mongrels (or really, the railses in the mongrels) are writing to the same file with no locking. I will have to read me some source code. Thanks for the tip! /David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20061011/ad59411a/attachment.html
On 10/11/06, Dee Zsombor <dee.zsombor at gmail.com> wrote:> > > Or use a custom script for well established logrotate. For once this is > already used to rotate other logs in the system, and will work correctly > unlike the above snippet prone to failure if multiple ruby processes try > to rotate at the same time.Yes, that would be preferrable. But all logrotate does is (1) rename the log file and (2, optional) send a signal to the application to let it know that the log file has been renamed, and hence, the application should close its file handle and open a new one. Rails and Mongrel don''t answer to a signal with the semantics of (2) AFAIK. Logrotate can also be used with applications that don''t answer to a signal but instead periodically (every five minutes or so) reopen their log file handle. My experiments with Rails in Mongrel indicate that Rails does not do this. But maybe I didn''t wait long enough? Either way, I don''t want to rely on Rails reopening the log files, since there is no guarantee that different processes will do it at the same time. So, thanks for your suggestion, but I''m afraid it won''t solve the problem. /David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20061011/9d985130/attachment.html
David Vrensk wrote:> Yes, that would be preferrable. But all logrotate does is (1) rename > the log file and (2, optional) send a signal to the application to let > it know that the log file has been renamed, and hence, the application > should close its file handle and open a new one. Rails and Mongrel > don''t answer to a signal with the semantics of (2) AFAIK.The same code you execute upon deploy to bounce your application servers can be used to a similar effect, with no more user noticeable downtime (or risk) as simple deployment. Just have to configure logrotate with a custom post rotate hook. Zsombor -- Company - http://primalgrasp.com Thoughts - http://deezsombor.blogspot.com
On 11/10/06 Dee Zsombor said:> The same code you execute upon deploy to bounce your application servers > can be used to a similar effect, with no more user noticeable downtime (or > risk) as simple deployment. Just have to configure logrotate with a > custom post rotate hook.I supervise mongrel_rails via runit. From there, if Rails would log to stdout I could use svlogd which would handle timestamps and rotation on its own. I''m on BSD so for now I''ve configured newsyslog to rotate the rails logs. Mike -- Michael P. Soulier <msoulier at digitaltorque.ca> "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction." --Albert Einstein -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://rubyforge.org/pipermail/mongrel-users/attachments/20061011/65cc5fbc/attachment.bin
On 10/11/06, Dee Zsombor <dee.zsombor at gmail.com> wrote:> > David Vrensk wrote: > > > Yes, that would be preferrable. But all logrotate does is (1) rename > > the log file and (2, optional) send a signal to the application to let > > it know that the log file has been renamed, and hence, the application > > should close its file handle and open a new one. Rails and Mongrel > > don''t answer to a signal with the semantics of (2) AFAIK. > > The same code you execute upon deploy to bounce your application servers > can be used to a similar effect, with no more user noticeable downtime (or > risk) as simple deployment. Just have to configure logrotate with a > custom post rotate hook.Ah yes. Unfortunately my app runs on a slow VPS, and the restart time is 30 seconds. So I really want Rails to behave like the other puppies. But I guess that I should take the question to the rails list since this isn''t a mongrel issue as such. Thank you all for your help! /David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20061012/5b2c17a8/attachment.html