Sha256: ecbceb058601c8a89edbc783588ba316dc2e6a1bf57bdd3687b786cd0955a47b

Contents?: true

Size: 950 Bytes

Versions: 13

Compression:

Stored size: 950 Bytes

Contents

require 'yell'
require 'colored'

module HTML
  class Proofer
    class Log
      include Yell::Loggable

      def initialize(verbose)
        log_level = verbose ? :debug : :info

        @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

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

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

      # dumb override to play nice with Typhoeus/Ethon
      def debug(message = nil)
        log(:debug, :yellow, message) unless message.nil?
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
html-proofer-2.4.2 lib/html/proofer/log.rb
html-proofer-2.4.1 lib/html/proofer/log.rb
html-proofer-2.4.0 lib/html/proofer/log.rb
html-proofer-2.3.0 lib/html/proofer/log.rb
html-proofer-2.2.0 lib/html/proofer/log.rb
html-proofer-2.1.0 lib/html/proofer/log.rb
html-proofer-2.0.6 lib/html/proofer/log.rb
html-proofer-2.0.5 lib/html/proofer/log.rb
html-proofer-2.0.4 lib/html/proofer/log.rb
html-proofer-2.0.3 lib/html/proofer/log.rb
html-proofer-2.0.2 lib/html/proofer/log.rb
html-proofer-2.0.1 lib/html/proofer/log.rb
html-proofer-2.0.0 lib/html/proofer/log.rb