Skip to content

An improved Logger replacement that logs to syslog. It is almost drop-in with a few caveats.

Notifications You must be signed in to change notification settings

ngmoco/syslog_logger

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SyslogLogger

github.com/ngmoco/sysloglogger

DESCRIPTION:

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

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

This particular Logger::Syslog 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.”

Version 1.6.7 takes a formatter as logger does and uses call to format the message.

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.)

RAILS_DEFAULT_LOGGER = Logger::Syslog.new

By default, Logger::Syslog uses the program name ‘rails’ and the facility ‘user’, but this can be changed via the arguments to Logger::Syslog.new:

RAILS_DEFAULT_LOGGER = Logger::Syslog.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.

About

An improved Logger replacement that logs to syslog. It is almost drop-in with a few caveats.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%