Class: HTMLProofer::Log
- Inherits:
-
Object
- Object
- HTMLProofer::Log
- Includes:
- Yell::Loggable
- Defined in:
- lib/html_proofer/log.rb
Constant Summary collapse
- STDOUT_LEVELS =
[:debug, :info, :warn].freeze
- STDERR_LEVELS =
[:error, :fatal].freeze
Instance Method Summary collapse
- #colorize(level, message) ⇒ Object
-
#debug(message = nil) ⇒ Object
dumb override to play nice with Typhoeus/Ethon.
-
#initialize(log_level) ⇒ Log
constructor
A new instance of Log.
- #log(level, message) ⇒ Object
- #log_with_color(level, message) ⇒ Object
Constructor Details
#initialize(log_level) ⇒ Log
Returns a new instance of Log.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/html_proofer/log.rb', line 13 def initialize(log_level) @logger = Yell.new( format: false, name: "HTMLProofer", \ level: "gte.#{log_level}", ) do |l| l.adapter(:stdout, level: "lte.warn") l.adapter(:stderr, level: "gte.error") end end |
Instance Method Details
#colorize(level, message) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/html_proofer/log.rb', line 32 def colorize(level, ) color = case level when :debug :cyan when :info :blue when :warn :yellow when :error, :fatal :red end if STDOUT_LEVELS.include?(level) || STDERR_LEVELS.include?(level) Rainbow().send(color) else end end |
#debug(message = nil) ⇒ Object
dumb override to play nice with Typhoeus/Ethon
53 54 55 |
# File 'lib/html_proofer/log.rb', line 53 def debug( = nil) log(:debug, ) unless .nil? end |
#log(level, message) ⇒ Object
24 25 26 |
# File 'lib/html_proofer/log.rb', line 24 def log(level, ) log_with_color(level, ) end |
#log_with_color(level, message) ⇒ Object
28 29 30 |
# File 'lib/html_proofer/log.rb', line 28 def log_with_color(level, ) @logger.send(level, colorize(level, )) end |