Skip to content

Instantly share code, notes, and snippets.

@jerome
Forked from eric/DISCLAIMER.md
Created December 17, 2011 11:03
Show Gist options
  • Save jerome/1489952 to your computer and use it in GitHub Desktop.
Save jerome/1489952 to your computer and use it in GitHub Desktop.
Log directly to Papertrail or any remote syslog target from Heroku

Setting up syslog logging on Heroku

1. Update your Gemfile

gem 'remote_syslog_logger'

2. Add the initializer

Take the example initializers (see below) for Rails 2 and 3 and put the correct one in config/initializers/.

3. Setup SYSLOG_URL environment variable

$ heroku config:add SYSLOG_URL=syslog://host.name.com:port/program

If you don't have a syslog target, get one for free from Papertrail.

That's it

On your next deploy you will be logging to that syslog host.

if ENV["SYSLOG_URL"]
require "remote_syslog_logger"
require "uri"
# redefine Rails.logger
def Rails.logger
@@logger ||= begin
url = URI.parse(ENV["SYSLOG_URL"])
logger = RemoteSyslogLogger.new(url.host, url.port, :program => url.path[1..-1])
logger.level = Logger::INFO
logger
end
end
# borrowed from Rails::Initializer#initialize_framework_logging
([ :active_record, :action_controller, :action_mailer ] & Rails.configuration.frameworks).each do |framework|
framework.to_s.camelize.constantize.const_get("Base").logger = Rails.logger
end
ActiveSupport::Dependencies.logger = Rails.logger
Rails.cache.logger = Rails.logger
end
if ENV["SYSLOG_URL"]
require "remote_syslog_logger"
require "uri"
url = URI.parse(ENV["SYSLOG_URL"])
logger = RemoteSyslogLogger.new(url.host, url.port, :program => url.path[1..-1])
logger.level = Logger::INFO
Rails.logger = Rails.application.config.logger = ActionController::Base.logger = Rails.cache.logger = logger
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment