Skip to content

Instantly share code, notes, and snippets.

@phil-monroe
Created December 19, 2012 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phil-monroe/4333393 to your computer and use it in GitHub Desktop.
Save phil-monroe/4333393 to your computer and use it in GitHub Desktop.
Things needed to log rails to papertrail.
class MultiIO
def initialize(*targets)
@targets = targets
end
def write(*args)
puts "writing"
@targets.each { |t| t.write(*args) }
end
def close
puts "closing"
@targets.each(&:close)
end
end
if Rails.env.development?
require File.expand_path('../../lib/multi_io', __FILE__)
papertrail = RemoteSyslogLogger::UdpSender.new('logs.papertrailapp.com', 58918, program: 'piston')
log_file = File.open(AppRunway::Application.config.paths['log'].first, "a")
log_file.sync = true
AppRunway::Application.config.colorize_logging = false
Rails.logger = Logger.new( ::MultiIO.new( log_file, papertrail ) )
Rails.logger.formatter = proc do |sev, time, prog, msg|
msg.gsub! /^\n*/, ""
pad = " " * (5-sev.length)
"[#{sev}]#{pad} #{time} - #{Process.pid}: #{msg}\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment