Skip to content

Instantly share code, notes, and snippets.

@garyharan
Last active June 3, 2024 15:06
Show Gist options
  • Save garyharan/6089778 to your computer and use it in GitHub Desktop.
Save garyharan/6089778 to your computer and use it in GitHub Desktop.
Simple rails logging output colorize
#!/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