¶ ↑
SyslogLoggergithub.com/DanaDanger/sysloglogger/tree
¶ ↑
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 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.rbconfig.gem "DanaDanger-syslog_logger", :lib => "syslog_logger", :source => "http://gems.github.com"
¶ ↑
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 facility “user”, but these can be changed the first time you instantiate a SyslogLogger:
RAILS_DEFAULT_LOGGER = SyslogLogger.new("mygreatapp", Syslog::LOG_LOCAL7)
¶ ↑
BSD syslog setup¶ ↑
/etc/syslog.confAdd 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.confAdd 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.confA 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); };
¶ ↑
StartingNow 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.
¶ ↑
INSTALL:$ gem sources -a http://gems.github.com (you only have to do this once) $ sudo gem install DanaDanger-syslog_logger
¶ ↑
LICENSE:Copyright © 2008-2009 Eric Hodel, Christopher Powell, Ian Lesperance, and Dana Contreras
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.