Class: HTML::Proofer::Log

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

Instance Method Summary collapse

Constructor Details

#initialize(verbose, verbosity = nil) ⇒ Log

Returns a new instance of Log.


9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/html/proofer/log.rb', line 9

def initialize(verbose, verbosity = nil)
  log_level = if verbosity.nil?
                verbose ? :debug : :info
              else
                verbosity
              end

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

Instance Method Details

#colorize(color, message) ⇒ Object


28
29
30
31
32
33
34
# File 'lib/html/proofer/log.rb', line 28

def colorize(color, message)
  if $stdout.isatty && $stderr.isatty
    Colored.colorize(message, foreground: color)
  else
    message
  end
end

#debug(message = nil) ⇒ Object

dumb override to play nice with Typhoeus/Ethon


37
38
39
# File 'lib/html/proofer/log.rb', line 37

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

#log(level, color, message) ⇒ Object


24
25
26
# File 'lib/html/proofer/log.rb', line 24

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