I was working on a Rails application recently that required the logs to be sent to remote log server. This blog is just a summary of the steps to get it working. I used Rails 2.0 and the development was done on Ubuntu.

The first thing was to get syslog-ng. Its more advanced than syslogd.

sudo apt-get install syslog-ng

The next step was to get the SysLogLogger tool to send the logs to syslog instead of a file. Go to the vendor directory of your application and get SysLogLogger using the following command.

curl http://rubyforge.org/frs/download.php/20520/SyslogLogger-1.4.0.tgz
-L | tar -zxvv

Assuming that you are working in the development environment , add this to the start of the development.rb file in the configuration directory

$:.unshift File.join(RAILS_ROOT, "vendor", "SyslogLogger-1.4.0", "lib")
require 'syslog_logger'
RAILS_DEFAULT_LOGGER = SyslogLogger.new(program_name = 'my-application')
config.logger = RAILS_DEFAULT_LOGGER

Locate the syslog.conf file in the etc directory and add these lines.

!my-rails-application
user.* /var/log/development.log


What this does is gets the logs that are sent to syslog from the rails application and writes it to the development.log file in /var/log/ dir

To get the changes working, restart the syslog service on Ubuntu by running the following command
sudo /etc/init.d/sysklogd restart

To send the logs to a remote log server instead of the log file use this in the syslog.conf file instead
user.* @address of remote log server

The log server should be configured to accept logs from remote systems. The syslogd file in the remote log server needs to be changed to show the following for this purpose

SYSLOGD="-r"

The syslogd file is located in the etc/default dir in Ubuntu. Since I had the log server configured already, I did not need to change the configuration. Please add comments on this post in case something is missing.

The log files can be rotated on a periodic basis (or depending on size) by configuring the logrotate.conf file in the etc dir.
See man logrotate for details.