Class: HTMLProofer::Log

Inherits:
Object
  • Object
show all
Includes:
Yell::Loggable
Defined in:
lib/html-proofer/log.rb

Instance Method Summary collapse

Constructor Details

#initialize(log_level) ⇒ Log

Returns a new instance of Log.



10
11
12
13
14
15
16
17
# File 'lib/html-proofer/log.rb', line 10

def initialize(log_level)
  @logger = Yell.new(format: false, \
                     name: 'HTMLProofer', \
                     level: "gte.#{log_level}") do |l|
    l.adapter :stdout, level: %i[debug info warn]
    l.adapter :stderr, level: %i[error fatal]
  end
end

Instance Method Details

#colorize(color, message) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/html-proofer/log.rb', line 38

def colorize(color, message)
  if $stdout.isatty && $stderr.isatty
    Rainbow(message).send(color)
  else
    message
  end
end

#debug(message = nil) ⇒ Object

dumb override to play nice with Typhoeus/Ethon



47
48
49
# File 'lib/html-proofer/log.rb', line 47

def debug(message = nil)
  log(:debug, message) unless message.nil?
end

#log(level, message) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/html-proofer/log.rb', line 19

def log(level, message)
  color = case level
          when :debug
            :cyan
          when :info
            :blue
          when :warn
            :yellow
          when :error, :fatal
            :red
          end

  log_with_color(level, color, message)
end

#log_with_color(level, color, message) ⇒ Object



34
35
36
# File 'lib/html-proofer/log.rb', line 34

def log_with_color(level, color, message)
  @logger.send level, colorize(color, message)
end