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, line 79
def detect_type(line)
  ORDER.find { |type| line =~ type::RE }
end
parse_format(format) click to toggle source
# File lib/nuggets/log_parser/apache.rb, line 67
def parse_format(format)
  re, items = '\A', []

  format.scan(DIRECTIVES_RE) { |h, c, e|
    i, r = DIRECTIVES[c]
    re << r.source << e.gsub(/\s/, '\s')
    items << i ||= h.downcase.tr('-', '_').to_sym
  }

  [Regexp.new(re), items]
end
register(name, format) click to toggle source
# File lib/nuggets/log_parser/apache.rb, line 56
def register(name, format)
  base = const_set(name, Module.new)

  re, items = parse_format(format)
  base.const_set(:RE,    re)
  base.const_set(:ITEMS, items)

  ORDER << base
  LogParser.register(base, self)
end

Public Instance Methods

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

  entry
end