class Fluent::ColorStripperOutput
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_color_stripper.rb, line 8 def configure(conf) super @tag = conf.fetch('tag') { raise ArgumentError, 'tag field is required to direct transformed logs to' } @strip_fields_arr = conf['strip_fields'].to_s.split(/\s*,\s*/).map do |field| field unless field.strip.empty? end.compact end
emit(tag, es, chain)
click to toggle source
# File lib/fluent/plugin/out_color_stripper.rb, line 18 def emit(tag, es, chain) es.each do |time, record| Engine.emit(@tag, time, format_record(record)) end chain.next end
Private Instance Methods
format_record(record)
click to toggle source
# File lib/fluent/plugin/out_color_stripper.rb, line 28 def format_record(record) record.each_with_object({}) do |(key, val), object| object[key] = if strip_field?(key) uncolorize(val) else val end end end
scan_for_colors(string)
click to toggle source
Scan for colorized string
# File lib/fluent/plugin/out_color_stripper.rb, line 50 def scan_for_colors(string) string.scan(/\033\[([0-9]+);([0-9]+);([0-9]+)m(.+?)\033\[0m|([^\033]+)/m) end
strip_field?(field)
click to toggle source
# File lib/fluent/plugin/out_color_stripper.rb, line 54 def strip_field?(field) @strip_fields_arr.empty? || @strip_fields_arr.include?(field) end
uncolorize(string)
click to toggle source
Return uncolorized string
# File lib/fluent/plugin/out_color_stripper.rb, line 41 def uncolorize(string) scan_for_colors(string).inject('') do |str, match| str << (match[3] || match[4]) end end