25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
848 B

module CryptCheck
class Logger
6 년 전
LEVELS = %i(trace debug info warning error fatal none)
def self.level=(level)
@@level = level.to_sym
end
self.level = ENV.fetch 'LOG', :info
def self.log(level, string=nil, output: $stdout, &block)
return unless enabled? level
output.puts(string ? string : block.call)
end
6 년 전
if Object.respond_to? :ai
def self.ap(name, object)
self.debug { "#{name} : #{object.ai}" }
end
else
def self.ap(name, object)
self.debug { "#{name} : #{object}" }
end
end
LEVELS.each do |level|
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def self.#{level}(string=nil, output: $stdout, &block)
self.log :#{level}, string, output: output, &block
end
RUBY_EVAL
end
private
def self.enabled?(level)
LEVELS.index(level) >= LEVELS.index(@@level)
end
end
end