Skip to content

Instantly share code, notes, and snippets.

@ggaglani
Created February 25, 2016 15:28
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 ggaglani/92a00f0e72a94c50311f to your computer and use it in GitHub Desktop.
Save ggaglani/92a00f0e72a94c50311f to your computer and use it in GitHub Desktop.
class Formatter
COLOR_MAP = {'DEBUG'=>'0;37', 'INFO'=>'32', 'WARN'=>'33', 'ERROR'=>'31', 'FATAL'=>'31', 'UNKNOWN'=>'37'}
def call(severity, time, progname, msg)
severity = sprintf("%-5s","#{severity}")
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S.") << time.usec.to_s[0..2].rjust(3)
color = COLOR_MAP[severity]
"\033[0;37m#{formatted_time}\033[0m [\033[#{color}m#{severity}\033[0m] #{msg.strip} (pid:#{$$})\n"
end
end
class Application
class << self
attr_accessor :logger
def logger
root = File.expand_path '..', __FILE__
logger ||= ActiveSupport::Logger.new(File.open("#{root}/log/standalone_app.log", 'a'))
logger.formatter = Formatter.new
logger
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment