class Herokulogs::Formatter
Constants
- FORMAT
- FORMATTER
- OUTPUT_FORMAT_OPTIONS
Attributes
output_format[R]
Public Class Methods
new(format_string)
click to toggle source
# File lib/herokulogs/formatter.rb, line 50 def initialize(format_string) output_format = format_string if output_format.empty? STDERR.puts "herokulogs format missing" exit(false) end @output_format = output_format.chars.map {|c| OUTPUT_FORMAT_OPTIONS[c]}.compact end
Public Instance Methods
format(line)
click to toggle source
# File lib/herokulogs/formatter.rb, line 59 def format(line) input = construct_input_hash(line) return unless input @output_format.map do |element| formatter = FORMATTER[element] if formatter.respond_to?(:call) formatter.call(input[element]) else formatter % input[element] end end.join(" ") end
Protected Instance Methods
construct_input_hash(line)
click to toggle source
# File lib/herokulogs/formatter.rb, line 74 def construct_input_hash(line) match = line.match(FORMAT) return unless match date, type, log_level, method, path, host, fwd, dyno, connect, service, status, bytes = match.captures { :date => date, :type => type, :log_level => log_level, :method => method, :path => path, :host => host, :fwd => fwd, :dyno => dyno, :connect => connect, :service => service, :status => status, :bytes => bytes } end