Module: Snapcrawl::LogHelpers
- Included in:
- PrettyLogger
- Defined in:
- lib/snapcrawl/log_helpers.rb
Constant Summary collapse
- SEVERITY_COLORS =
{ 'INFO' => :blue, 'WARN' => :yellow, 'ERROR' => :red, 'FATAL' => :red, 'DEBUG' => :cyan }
Instance Method Summary collapse
- #actual_colors ⇒ Object
- #colors? ⇒ Boolean
- #empty_colors ⇒ Object
- #log_colors ⇒ Object
- #log_colors! ⇒ Object
- #log_formatter ⇒ Object
- #tty? ⇒ Boolean
Instance Method Details
#actual_colors ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/snapcrawl/log_helpers.rb', line 27 def actual_colors { red: "\e[31m", green: "\e[32m", yellow: "\e[33m", blue: "\e[34m", purple: "\e[35m", cyan: "\e[36m", underlined: "\e[4m", bold: "\e[1m", none: "", reset: "\e[0m" } end |
#colors? ⇒ Boolean
45 46 47 48 49 50 51 |
# File 'lib/snapcrawl/log_helpers.rb', line 45 def colors? if Config.log_color == 'auto' tty? else Config.log_color end end |
#empty_colors ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/snapcrawl/log_helpers.rb', line 36 def empty_colors { red: "", green: "", yellow: "", blue: "", purple: "", cyan: "", underlined: "", bold: "", none: "", reset: "" } end |
#log_colors ⇒ Object
19 20 21 |
# File 'lib/snapcrawl/log_helpers.rb', line 19 def log_colors @log_colors ||= log_colors! end |
#log_colors! ⇒ Object
23 24 25 |
# File 'lib/snapcrawl/log_helpers.rb', line 23 def log_colors! colors? ? actual_colors : empty_colors end |
#log_formatter ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/snapcrawl/log_helpers.rb', line 11 def log_formatter proc do |severity, _time, _prog, | severity_color = SEVERITY_COLORS[severity] "%{#{severity_color}}#{severity.rjust 5}%{reset} : #{message}\n" % log_colors end end |
#tty? ⇒ Boolean
53 54 55 |
# File 'lib/snapcrawl/log_helpers.rb', line 53 def tty? ENV['TTY'] == 'on' ? true : ENV['TTY'] == 'off' ? false : $stdout.tty? end |