Class: EZproxy::Log::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/ezproxy/log/format.rb

Constant Summary collapse

ATTRIBUTES =

Array containing each log format An attribute must contain a :token, :regexp, and :label. Optional keys include :post

[
  {:token => '%h',
   :regexp => /([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/,
   :label => 'remote_host'},
  {:token => '%l',
   :regexp => /(-)/,
   :label  => nil},
  {:token => '%u',
   :regexp => /(.*)/,
   :label  => 'username'},
  {:token => '%t',
   :regexp => /\[(.*)\]/,
   :post   => Proc.new {|x| x[11] = ' '},
   :label  => 'happened_at'},
  {:token => '%r',
   :regexp => /(.*)/,
   :label  => 'http_request'},
  {:token => '%s',
   :regexp => /(\d+)/,
   :label  => 'http_status'},
  {:token => '%b',
   :regexp => /(\d+)/,
   :label  => 'http_bytes'},
  {:token => '%U',
   :regexp => /([^ ]+)/,
   :label  => 'http_url'},
  {:token => '%{ezproxy-session}i',
   :regexp => /(.*)/,
   :label  => 'ezproxy_session'}
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ Format

Returns a new instance of Format.



40
41
42
# File 'lib/ezproxy/log/format.rb', line 40

def initialize(s)
  @format = s
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



4
5
6
# File 'lib/ezproxy/log/format.rb', line 4

def format
  @format
end

Instance Method Details

#defined_attributesObject



53
54
55
56
57
58
59
60
# File 'lib/ezproxy/log/format.rb', line 53

def defined_attributes
  l = []
  ATTRIBUTES.each do |attr|
    l[@format.index(attr[:token])] = attr if @format.include? attr[:token]
  end

  l.compact
end

#to_regexObject



44
45
46
47
48
49
50
51
# File 'lib/ezproxy/log/format.rb', line 44

def to_regex
  regex = @format.clone
  ATTRIBUTES.each do |regexp|
    regex.gsub!(regexp[:token], regexp[:regexp].source)
  end

  Regexp.compile(regex)
end