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


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

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


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

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

#debug(message = nil) ⇒ Object

dumb override to play nice with Typhoeus/Ethon


45
46
47
# File 'lib/html-proofer/log.rb', line 45

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

#log(level, message) ⇒ Object


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

def log(level, message)
  color = case level
          when :debug
            :light_blue
          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


32
33
34
# File 'lib/html-proofer/log.rb', line 32

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