Skip to content

Instantly share code, notes, and snippets.

@mheffner
Created June 20, 2011 23:06
Show Gist options
  • Save mheffner/1036817 to your computer and use it in GitHub Desktop.
Save mheffner/1036817 to your computer and use it in GitHub Desktop.
Setting up syslog logging on Heroku with Sinatra 1.2.x

Setting up syslog logging on Heroku with Sinatra 1.2.x

1. Update your Gemfile to include:

gem 'remote_syslog_logger'

2. Add the file remote_syslog.rb below to your Sinatra app as lib/remote_syslog.rb.

3. Modify your config.ru to match the example one below.

4. Setup REMOTE_SYSLOG_URI environment variable

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

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. Logs will use the hostname format: {APP_NAME}-{DYNO_NAME}.

require "rubygems"
require "bundler"
Bundler.require
if ENV['REMOTE_SYSLOG_URI']
require 'lib/remote_syslog'
logger = RemoteSyslog.new(ENV['REMOTE_SYSLOG_URI'])
use Rack::CommonLogger, logger
end
require "hello-world"
run HelloWorld::Application
require 'uri'
class RemoteSyslog
def initialize(uri)
uri = URI.parse(uri)
@logger = RemoteSyslogLogger.
new(uri.host, uri.port,
:local_hostname => "#{ENV['APP_NAME']}-#{ENV['PS']}")
end
def write(str)
@logger.info(str)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment