Class: MyStuff::Logger::ReaderFilters::PriorityColors

Inherits:
MyStuff::Logger::ReaderFilter show all
Defined in:
lib/my_stuff/logger/reader_filters/priority_colors.rb

Overview

Highlight info/warning/error/fatal in different colors.

Instance Method Summary collapse

Methods inherited from MyStuff::Logger::ReaderFilter

to_proc

Instance Method Details

#filter_line(line, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/my_stuff/logger/reader_filters/priority_colors.rb', line 6

def filter_line line, options = {}
 return line unless options[:colorize]

  line = line.dup

  # Colorize, based on priority
  line.sub! /^([IWEF]) ([0-9]+ \[[^>]+>)/ do |prefix|
    # Set the color
    colors = {
                     # debug  => meh
      'I' => '32',   # info   => green
      'W' => '33',   # warn   => yellow
      'E' => '31',   # errror => red
      'F' => '1;31', # fatal  => bold + red
    }
    # Reset it once the standard info is done
    prefix.sub! /^[IWEF]/ do |pri|
      "\e[%sm%s" % [colors[pri], pri]
    end
    prefix.sub! '>', ">\e[0m"
    prefix
  end
  line
end