Skip to content

Instantly share code, notes, and snippets.

@piclez
Created October 31, 2008 18:06
Show Gist options
  • Save piclez/21373 to your computer and use it in GitHub Desktop.
Save piclez/21373 to your computer and use it in GitHub Desktop.
# lib/color_logger.rb
module Merb
class Logger
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white # 30 = black 31 = red 32 = green 33 = yellow blue 34 = 35 = magenta 36 = cyan 37 = white
Colors = Mash.new({
:fatal => 31,
:error => 31,
:warn => 33,
:info => 38,
:debug => 36
})
Levels.each_pair do |name, number|
class_eval <<-LEVELMETHODS, __FILE__, __LINE__
def #{name}(message = nil)
self << "[1;#{Colors[name]}m%s" % message if #{number} >= level
self
end
def #{name}!(message = nil)
self << "[1;#{Colors[name]}m%s" % message if #{number} >= level
flush if #{number} >= level
self
end
LEVELMETHODS
end
def my_debug(message = nil)
self << "%s" % message
self
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment