You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

logger.rb 621B

12345678910111213141516171819202122232425262728
  1. module CryptCheck
  2. class Logger
  3. LEVELS = %i(trace debug info warning error fatal none)
  4. @@level = :info
  5. def self.level=(level)
  6. @@level = level
  7. end
  8. def self.log(level, string=nil, output: $stdout, &block)
  9. return unless enabled? level
  10. output.puts(string ? string : block.call)
  11. end
  12. LEVELS.each do |level|
  13. class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
  14. def self.#{level}(string=nil, output: $stdout, &block)
  15. self.log :#{level}, string, output: output, &block
  16. end
  17. RUBY_EVAL
  18. end
  19. private
  20. def self.enabled?(level)
  21. LEVELS.index(level) >= LEVELS.index(@@level)
  22. end
  23. end
  24. end