Module: Snapcrawl::LogHelpers

Includes:
Colsole
Included in:
PrettyLogger
Defined in:
lib/snapcrawl/log_helpers.rb

Constant Summary collapse

SEVERITY_COLORS =
{
  'INFO'  => :b,
  'WARN'  => :y,
  'ERROR' => :r,
  'FATAL' => :r,
  'DEBUG' => :c,
}

Instance Method Summary collapse

Instance Method Details

#log_formatterObject



15
16
17
18
19
20
21
# File 'lib/snapcrawl/log_helpers.rb', line 15

def log_formatter
  proc do |severity, _time, _prog, message|
    severity_color = SEVERITY_COLORS[severity]
    line = "#{severity_color}`#{severity.rjust 5}` : #{message}\n"
    use_colors? ? colorize(line) : strip_colors(line)
  end
end

#tty?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
# File 'lib/snapcrawl/log_helpers.rb', line 27

def tty?
  case ENV['TTY']
  when 'on' then true
  when 'off' then false
  else
    $stdout.tty?
  end
end

#use_colors?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/snapcrawl/log_helpers.rb', line 23

def use_colors?
  @use_colors ||= (Config.log_color == 'auto' ? tty? : Config.log_color)
end