Skip to content

Instantly share code, notes, and snippets.

@nlim
Forked from eric/DISCLAIMER.md
Created July 12, 2012 17:24
Show Gist options
  • Select an option

  • Save nlim/3099478 to your computer and use it in GitHub Desktop.

Select an option

Save nlim/3099478 to your computer and use it in GitHub Desktop.
Rails 3, Log directly to PaperTrail Remote Syslog

Setting up logging to PaperTrail Remote Syslog in Rails 3

1. Update your Gemfile

gem 'remote_syslog_logger'

2. Add the initializer

Define constants in `config/initializers/papertrail.rb`.

If you don't have a syslog target, get one for free from [Papertrail](https://papertrailapp.com/).

That's it !!!

On your next deploy you will be logging to that syslog host.
class LoggedClass
attr_reader :logger
def initialize
url = PAPERTRAIL_LOG_URI
@logger = RemoteSyslogLogger.new(url.host, url.port, :program => "#{self.class} Log")
@logger.level = PAPERTRAIL_LOG_LEVEL
end
def task
begin
run_fatal_method
rescue Exception => e
logger.fatal("#{self.class} Task Failed: #{e.inspect}")
end
end
def run_fatal_method
1/0
end
end
PAPERTRAIL_LOG_URI = URI.parse("syslog://blahblahblah")
case Rails.env.to_sym
when :test
PAPERTRAIL_LOG_LEVEL = Logger::ERROR
when :production
PAPERTRAIL_LOG_LEVEL = Logger::WARN
when :staging
PAPERTRAIL_LOG_LEVEL = Logger::INFO
else
PAPERTRAIL_LOG_LEVEL = Logger::DEBUG
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment