Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Jason Hutchens June 20, 2013
file 38 lines (29 sloc) 0.877 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
require 'logger'
require 'English'
require 'socket'

# A logger for use with pl_analyze and other tools that expect syslog-style log output.
class Hodel3000CompliantLogger < Logger

  ##
  # Note: If you are using FastCGI you may need to hard-code the hostname here instead of using Socket.gethostname

  def format_message(severity, timestamp, progname, msg)
    "#{timestamp.strftime("%b %d %H:%M:%S")} #{hostname} rails[#{process_id}]: #{msg2str(msg).gsub(/\n/, '').lstrip}\n"
  end

  private

  def hostname
    @parsed_hostname ||= Socket.gethostname.split('.').first
  end

  def process_id
    @process_id ||= "#{$PID}:#{Thread.current.object_id}"
  end

  def msg2str(msg)
    case msg
    when ::String
      msg
    when ::Exception
      "#{ msg.message } (#{ msg.class }): " <<
      (msg.backtrace || []).join(" | ")
    else
      msg.inspect
    end
  end

end
Something went wrong with that request. Please try again.