How to get rails to log in a way that plays nice with the rest of your debian system.
install SyslogLogger¶
Rails can use many different logging libraries. If you want to pass on the logging responsibility to syslog, the library needed is called “SyslogLogger”
# gem install SyslogLogger
In order to get our rails app to use this logger, add this to the config/environments/production.rb
file:
codetitle. config/environments/production.rb
begin
require 'syslog_logger'
RAILS_DEFAULT_LOGGER = SyslogLogger.new
rescue LoadError => exc
# SyslogLogger is not installed
end
then restart the rails application.
configure syslog-ng¶
Now rails is logging to syslog. If you want this to go to a custom log file, then you need to install a syslog replacement that can filter on application name. Syslog-ng works nicely.
Here is an example of how you might configure this:
codetitle. /etc/syslog-ng/sylog-ng.conf
filter f_rails { program("rails"); };
destination d_rails { file("/var/log/rails.log"); };
log {
source(s_all);
filter(f_rails);
destination(d_rails);
flags(final);
};
configure logrotate¶
to be written…