Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
An improved Logger replacement that logs to syslog. It is almost drop-in with a few caveats.
Ruby
Tag: v1.6.5

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
config
lib
test
.gitignore
Manifest
README.rdoc
Rakefile
VERSION

README.rdoc

SyslogLogger

github.com/ngmoco/sysloglogger

DESCRIPTION:

SyslogLogger is a Logger replacement that logs to syslog. It is almost drop-in with a few caveats. You can add SyslogLogger to your Rails production environment to aggregate logs between multiple machines.

NOTE! You can only set the SyslogLogger program name and facility when you initialize SyslogLogger for the first time. This is a limitation of the way SyslogLogger uses syslog (and in some ways, a limitation of the way syslog(3) works). Attempts to change SyslogLogger's program name or facility after the first initialization will be ignored.

This particular SyslogLogger improves the original by correctly mapping Rails log severities to the Syslog counterparts. It also adds the ability to select a syslog facility other than “user.”

SYNOPSIS:

config/environment.rb

config.gem 'syslog_logger'

Gemfile

gem 'syslog-logger'

config/environments/production.rb

(Only this environment, since you probably only want to enable it for Production, and not Test or Development.)

require 'syslog_logger'
RAILS_DEFAULT_LOGGER = SyslogLogger.new

By default, SyslogLogger uses the program name 'rails' and the facility 'user', but this can be changed via the arguments to SyslogLogger.new:

RAILS_DEFAULT_LOGGER = SyslogLogger.new('mygreatapp', Syslog::LOG_LOCAL7)

BSD syslog setup

/etc/syslog.conf

Add the following lines:

!rails
*.*                                             /var/log/production.log

Or, in Mac OS X:

local7.*                                        /var/log/production.log

Then touch /var/log/production.log and signal syslogd with a HUP (killall -HUP syslogd, on FreeBSD and OS X).

/etc/newsyslog.conf

Add the following line:

/var/log/production.log                 640  7     *    @T00  Z

This creates a log file that is rotated every day at midnight, gzip'd, then kept for 7 days. Consult newsyslog.conf(5) for more details.

syslog-ng setup

syslog-ng.conf

A basic setup:

destination rails_log { file("/var/log/production.log"); };
filter f_rails { program("rails.*"); };
log { source(src); filter(f_rails); destination(rails_log); };

A more advanced setup with formatting, etc:

destination rails { file("/var/log/rails_apps" owner("rails") group("rails") perm(0664) template("$DATE $HOST $PROGRAM [$LEVEL] $MSGONLY\n") template_escape(no) ); };
filter f_rails    { (program("railsappone") or program("railsapptwo")) and not match("SQL ") and not match("SELECT") and not match("INSERT INTO") and not match("UPDATE"); };
log { source(src); filter(f_rails); destination(rails); };

Starting

Now restart your Rails app. Your production logs should now be showing up in /var/log/production.log. If you have mulitple machines, you can log them all to a central machine with remote syslog logging for analysis. Consult your syslogd(8) manpage for further details.

LICENSE:

Copyright © 2008, 2009 Eric Hodel, Christopher Powell, Ian Lesperance,

Dana Contreras, Brian Smith, Ashley Martens

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.