Created
May 18, 2016 10:23
-
-
Save joshski/63be506bc1d7e8175dc8865a05a7760d to your computer and use it in GitHub Desktop.
A nicer rails logger for development time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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