class Fluent::TextParser::HerokuParser
Public Class Methods
new()
click to toggle source
desc 'The delimiter character (or string) of TSV values' config_param :delimiter, :string, default: “t” desc 'The delimiter character between field name and value' config_param :label_delimiter, :string, default: “:” config_set_default :time_key, 'time'
Calls superclass method
# File lib/fluent/plugin/parser_heroku_parser.rb, line 28 def initialize super end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/parser_heroku_parser.rb, line 32 def configure(conf) super end
parse(text)
click to toggle source
# File lib/fluent/plugin/parser_heroku_parser.rb, line 36 def parse(text) text =~ /^([^ ]*\s+[^ ]*\s+[^ ]*?)\s([^ ]*?)\s([a-zA-Z0-9_\/\.\-]*)\[([a-zA-Z0-9\.]+)\]?\s(.*)$/ record = { access_time: $1, host: $2, ident: $3, pid: $4 }.merge(parse_message($5)) return Time.now.to_i, record end
parse_message(msg)
click to toggle source
TODO: 取得するログを config で指定できるようにする
# File lib/fluent/plugin/parser_heroku_parser.rb, line 43 def parse_message(msg) all = {} [ '(sock)=(.*?)\s', '(at)=(.*?)\s', '(code)=(.*?)\s', '(desc)="(.*?)"\s', '(method)=(.+?)\s', '(path)="(.+?)"\s', '(host)=(.+?)\s', '(request_id)=(.+?)\s', '(fwd)="([0-9\.]+?)"\s', '(dyno)=(.+?)\s', '(connect)=([0-9]+?)ms\s', '(service)=([0-9]+?)ms\s', '(status)=([0-9]+?)\s', '(bytes)=([0-9]+?)\s', '(tls_version)=(.+)', ].each{|reg_str| all = all.merge(to_hash(msg, reg_str)) } all = all.merge(parse_path(msg)) end
parse_path(msg)
click to toggle source
# File lib/fluent/plugin/parser_heroku_parser.rb, line 67 def parse_path(msg) p = msg.scan(/path="(.+?)"\s/).map{|v| v[0].split('?')}.flatten p.length == 2 ? {url: p[0], query: p[1]} : {url: p[0]} end
to_hash(msg, regexp_string)
click to toggle source
# File lib/fluent/plugin/parser_heroku_parser.rb, line 72 def to_hash(msg, regexp_string) msg.scan(/#{regexp_string}/).map{|k, v| [k.to_sym,v.to_s]}.to_h end