Skip to content

Instantly share code, notes, and snippets.

@mhanne
Created December 4, 2011 17:44
Show Gist options
  • Save mhanne/1430799 to your computer and use it in GitHub Desktop.
Save mhanne/1430799 to your computer and use it in GitHub Desktop.
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