module Nuggets::LogParser::Apache

Constants

DEFAULT_RE
DIRECTIVES
DIRECTIVES_RE
ORDER

Public Class Methods

detect_type(line) click to toggle source
   # File lib/nuggets/log_parser/apache.rb
79 def detect_type(line)
80   ORDER.find { |type| line =~ type::RE }
81 end
parse_format(format) click to toggle source
   # File lib/nuggets/log_parser/apache.rb
67 def parse_format(format)
68   re, items = '\A', []
69 
70   format.scan(DIRECTIVES_RE) { |h, c, e|
71     i, r = DIRECTIVES[c]
72     re << r.source << e.gsub(/\s/, '\\s')
73     items << i ||= h.downcase.tr('-', '_').to_sym
74   }
75 
76   [Regexp.new(re), items]
77 end
register(name, format) click to toggle source
   # File lib/nuggets/log_parser/apache.rb
56 def register(name, format)
57   base = const_set(name, Module.new)
58 
59   re, items = parse_format(format)
60   base.const_set(:RE,    re)
61   base.const_set(:ITEMS, items)
62 
63   ORDER << base
64   LogParser.register(base, self)
65 end

Public Instance Methods

parse_line(line, entry = {}) { || ... } click to toggle source
   # File lib/nuggets/log_parser/apache.rb
90 def parse_line(line, entry = {})
91   if md = self::RE.match(line)
92     self::ITEMS.each_with_index { |k, i| entry[k] = md[i + 1] }
93     yield if block_given?
94   end
95 
96   entry
97 end