Class: HTMLProofer::Log
- Inherits:
-
Object
- Object
- HTMLProofer::Log
- Includes:
- Yell::Loggable
- Defined in:
- lib/html-proofer/log.rb
Constant Summary collapse
- STDOUT_LEVELS =
%i[debug info warn].freeze
- STDERR_LEVELS =
%i[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 |
# 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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/html-proofer/log.rb', line 30 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) && $stdout.isatty) || \ (STDERR_LEVELS.include?(level) && $stderr.isatty) Rainbow().send(color) else end end |
#debug(message = nil) ⇒ Object
dumb override to play nice with Typhoeus/Ethon
51 52 53 |
# File 'lib/html-proofer/log.rb', line 51 def debug( = nil) log(:debug, ) unless .nil? end |
#log(level, message) ⇒ Object
22 23 24 |
# File 'lib/html-proofer/log.rb', line 22 def log(level, ) log_with_color(level, ) end |
#log_with_color(level, message) ⇒ Object
26 27 28 |
# File 'lib/html-proofer/log.rb', line 26 def log_with_color(level, ) @logger.send level, colorize(level, ) end |