Created
December 4, 2011 17:44
-
-
Save mhanne/1430799 to your computer and use it in GitHub Desktop.
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 Logger | |
LEVELS = [:debug, :info, :warn, :error, :fatal] | |
attr_accessor :level | |
def initialize(name) | |
@name = name | |
@level = :info | |
end | |
def level= level | |
@level = level.is_a?(Fixnum) ? LEVELS[level] : level.to_sym | |
end | |
LEVELS.each do |level| | |
define_method(level) do |*msg, &block| | |
return if LEVELS.index(level.to_sym) < LEVELS.index(@level.to_sym) | |
msg = block ? block.call : msg.join | |
puts "#{@name} #{level}: #{msg}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment