Skip to content

Instantly share code, notes, and snippets.

@garyharan
Last active October 12, 2021 13:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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