Class: EZproxy::Log::Format
- Inherits:
-
Object
- Object
- EZproxy::Log::Format
- 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
-
#format ⇒ Object
Returns the value of attribute format.
Instance Method Summary collapse
- #defined_attributes ⇒ Object
-
#initialize(s) ⇒ Format
constructor
A new instance of Format.
- #to_regex ⇒ Object
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
#format ⇒ Object
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_attributes ⇒ Object
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_regex ⇒ Object
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 |