Hi all, I would like to have the rails logs roll over daily so I always have a fresh log to look at. It would be nice to have the logs archived by date - i.e. 2005-07-10/production.log. Does rails have a built in way to do this? So far I have thought of using cronolog.org to handle this for me, but I don''t know how to configure rails to pipe the log to this command. The other idea was to change the default Logger in environment.rb to use Log4R since it has support a RollingFileOutputter, and the emailer is nice too. Has anyone ever set this up? What''s the "rails" way? Thanks! --Dave.
On 7/10/05, David Teare <dteare-LXYvB7aEQDJCkLs28/y7ANBPR1lH4CV8@public.gmane.org> wrote:> Hi all, > > I would like to have the rails logs roll over daily so I always have > a fresh log to look at. It would be nice to have the logs archived > by date - i.e. 2005-07-10/production.log. Does rails have a built in > way to do this? > > So far I have thought of using cronolog.org to handle this > for me, but I don''t know how to configure rails to pipe the log to > this command. > > The other idea was to change the default Logger in environment.rb to > use Log4R since it has support a RollingFileOutputter, and the > emailer is nice too. > > Has anyone ever set this up? What''s the "rails" way?I think the "rails" way is to just use Log4r or something similar. Why bother to build a logging module if it works fine? Any suggestions are highly welcome though, because I''m only *planning* to use log4r. -- rick techno-weenie.net
A daily execution of logrotate with a postrotate block moving the rotated file to one with a datestamp (date -I -r production.log) would work, without the overhead of a pipe for cronolog. Another option would be cronosplit, part of the cronolog package, which can be used via a cron job. David Teare wrote:> Hi all, > > I would like to have the rails logs roll over daily so I always have a > fresh log to look at. It would be nice to have the logs archived by > date - i.e. 2005-07-10/production.log. Does rails have a built in way > to do this? > > So far I have thought of using cronolog.org to handle this for > me, but I don''t know how to configure rails to pipe the log to this > command. > > The other idea was to change the default Logger in environment.rb to > use Log4R since it has support a RollingFileOutputter, and the emailer > is nice too. > > Has anyone ever set this up? What''s the "rails" way? > > Thanks! > --Dave. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > lists.rubyonrails.org/mailman/listinfo/rails
Rick Olson wrote:>I think the "rails" way is to just use Log4r or something similar. >Why bother to build a logging module if it works fine? Any >suggestions are highly welcome though, because I''m only *planning* to >use log4r. > > > >Use logrotate, this is a standard way to rotate logs on unix systems, it can be configured to handle logs as you wish. It usually takes care of all your system logs, so instead of adding another log managing utility you probably want to use something that is already there. "One Program to Rotate Them All" :) -- Best Karol Hosiawa
I like the idea of not adding Yet Another log management utility, but it seems to me logrotate requires you to recycle your server every time it runs. That''s why I was leaning towards cronolog. Is there an easier way that restarting lighty every time the logs are archived? On 11-Jul-05, at 6:53 AM, Karol Hosiawa wrote:> Rick Olson wrote: > > >> I think the "rails" way is to just use Log4r or something similar. >> Why bother to build a logging module if it works fine? Any >> suggestions are highly welcome though, because I''m only *planning* to >> use log4r. >> >> >> >> > Use logrotate, this is a standard way to rotate logs on unix systems, > it can be configured to handle logs as you wish. > It usually takes care of all your system logs, so instead of adding > another > log managing utility you probably want to use something that is > already there. > "One Program to Rotate Them All" :) > > -- > Best > Karol Hosiawa > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > lists.rubyonrails.org/mailman/listinfo/rails >
Log4r is the way to go. ActiveRecord is specifically designed to work with it. Just change the logger to a Log4r logger and you can setup any type of rotating, emailing, etc,etc you wish. -- John W Higgins wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
On Jul 11, 2005, at 7:14 AM, John Higgins wrote:> Log4r is the way to go. ActiveRecord is specifically designed to work > with it. Just change the logger to a Log4r logger and you can setup > any type of rotating, emailing, etc,etc you wish.FWIW, the standard Logger lib also supports log rotation. logger = Logger.new(''foo.log'', ''daily'') You can read more about the available options at tinyurl.com/cqmfy (at ruby-doc.org) However, please note (and this IS IMPORTANT): you cannot reliably use Logger''s rotation feature if you are using multiple processes writing to the same log file (such as will be the instance when you are dealing with FCGI), because you can wind up with race conditions where multiple processes are each trying to rotate the log themselves. (I don''t know if Log4r is more reliable in this circumstance or not.) In such a situation, you''ll want to deal with an external process to manage logging, using (for instance) Eric Hodel''s "syslog_logger" that comes with the production_log_analyzer gem. - Jamis
On 7/11/05, David Teare <dteare-LXYvB7aEQDJCkLs28/y7ANBPR1lH4CV8@public.gmane.org> wrote:> I like the idea of not adding Yet Another log management utility, but > it seems to me logrotate requires you to recycle your server every > time it runs. That''s why I was leaning towards cronolog. > > Is there an easier way that restarting lighty every time the logs are > archived?logrotate doesn''t require you to recycle your server. It''s just an option: iain.cx/src/logrotate Still, it seems like this would cause problems if your website happens to get hit while it''s processing. Actually, I think the default logger just starts a new file if it''s not there, so this is a moot point? -- rick techno-weenie.net