Skip to content

Instantly share code, notes, and snippets.

@joshski
Created May 18, 2016 10:23
Show Gist options
  • Save joshski/63be506bc1d7e8175dc8865a05a7760d to your computer and use it in GitHub Desktop.
Save joshski/63be506bc1d7e8175dc8865a05a7760d to your computer and use it in GitHub Desktop.
A nicer rails logger for development time
class QuickGlanceFormatter < ActiveSupport::Logger::SimpleFormatter
def call(severity, timestamp, progname, message)
m = message + "\n"
if m =~ /^Started ([A-Z]+) (.+)/m
"\033[34m\n#{$1} #{$2}\033[0m"
elsif m =~ /^Processing by (.+)/m
"\033[34m↳ #{$1}\033[0m"
elsif m =~ /^Completed (\d\d\d) (.+)/m
status = $1
rest = $2
if status =~ /(2|3)\d\d/
"\033[32m✓ #{status} #{rest}\033[0m"
else
"\033[31m✗ #{status} #{rest}\033[0m"
end
else
m
end
end
end
config.logger = Logger.new(STDOUT)
config.logger.formatter = QuickGlanceFormatter.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment