class Larch::Logger
Constants
- LEVELS
Attributes
level[R]
output[R]
Public Class Methods
new(level = :info, output = $stdout)
click to toggle source
# File lib/larch/logger.rb, line 16 def initialize(level = :info, output = $stdout) self.level = level.to_sym self.output = output end
Public Instance Methods
const_missing(name)
click to toggle source
# File lib/larch/logger.rb, line 21 def const_missing(name) return LEVELS[name] if LEVELS.key?(name) raise NameError, "uninitialized constant: #{name}" end
level=(level)
click to toggle source
# File lib/larch/logger.rb, line 31 def level=(level) raise ArgumentError, "invalid log level: #{level}" unless LEVELS.key?(level) @level = level end
log(level, msg)
click to toggle source
# File lib/larch/logger.rb, line 36 def log(level, msg) return true if LEVELS[level] > LEVELS[@level] || msg.nil? || msg.empty? @output.puts "[#{Time.new.strftime('%H:%M:%S')}] [#{level}] #{msg}" true rescue => e false end
method_missing(name, *args)
click to toggle source
# File lib/larch/logger.rb, line 26 def method_missing(name, *args) return log(name, *args) if LEVELS.key?(name) raise NoMethodError, "undefined method: #{name}" end
output=(output)
click to toggle source
# File lib/larch/logger.rb, line 45 def output=(output) raise ArgumentError, "output must be an instance of class IO" unless output.is_a?(IO) @output = output end