Last active
June 3, 2024 15:06
-
-
Save garyharan/6089778 to your computer and use it in GitHub Desktop.
Simple rails logging output colorize
This file contains 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
#!/usr/bin/env ruby -w | |
# SETUP: | |
# (assumes ~/bin/ is in your path) | |
# cp colorize.rb ~/bin/colorize | |
# chmod +x ~/bin/colorize | |
# USAGE: | |
# tail -f log/development.log | colorize | |
class String | |
COLORS = { | |
black: 30, | |
blue: 34, | |
yellow: 33, | |
cyan: 36, | |
green: 32, | |
magenta: 35, | |
red: 31, | |
white: 37 | |
} | |
COLORS.each do |color, code| | |
define_method(color) do | |
"\e[#{code}m#{self.gsub("\n", "")}\033[0m" | |
end | |
end | |
end | |
STDIN.each do |line| | |
puts case line | |
when /\[ERROR/i, /\[FATAL/i | |
line.red | |
when /\[WARNING/i | |
line.orange | |
when /\[INFO/i | |
line.yellow | |
else | |
line | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment