Using rsyslogd in Rails 3.0
Asked Answered
H

1

7

I am running a couple of Rails 3.0 sites on a Debian server. Currently all logs go into RAILS_ROOT/log/production.log (RAILS_ROOT for each site)

I would like to change this, so that all logging goes through rsyslog and is placed in:

/var/log/rails/site1.log
/var/log/rails/site2.log
etc.

And also to have these logs auto-rotated every day.

How is this done?

/ Carsten

Homogenize answered 29/5, 2012 at 7:10 Comment(0)
C
15

In the past I have used the syslog-logger gem for this

You can set this up in an initializer:

config.logger = Logger::Syslog.new("site1", Syslog::LOG_LOCAL5)

In recent ruby versions, there's also syslog/logger in the standard library - usage is pretty much the same.

To start logging to syslog rather than the default text file. What happens next is a syslog configuration thing - you need to create rsyslog rules that define where your data goes

The simplest possible thing would be something like

!site1 /var/log/site1.log

Which directs everything with the program name "site1" ( the first argument to Logger::Syslog).

There is lots more you can do, for example you could forward log messages across to a central logging server that aggregates them all into one file so tht you don't have Iook at one log file for each of your app instances.

For log rotation I use logrotate - I believe rsyslog can actually handle that sort of stuff internally but I don't know the details.

Chloris answered 29/5, 2012 at 17:26 Comment(3)
So sorry that I have not yet commented on this - hadn't seen, that there was an answer. I will try this out next week - thanks!Homogenize
Syslog::LOG_LOCAL5 - isn't there a typo here?Homogenize
Just missing a closing ). Other than that came straight from a production app's config file.Chloris

© 2022 - 2024 — McMap. All rights reserved.