Class: NginxUtils::Logreader

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/nginx_utils/logreader.rb

Instance Method Summary collapse

Constructor Details

#initialize(log, options = {}) ⇒ Logreader

Returns a new instance of Logreader.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/nginx_utils/logreader.rb', line 7

def initialize(log, options={})
  @log = File.open(log)

  if options[:parser]
    if options[:parser].is_a? Regexp
      @format = :custom
      @parser = options[:parser]
    else
      raise ArgumentError, "invalid argument"
    end
  else
    @format = options[:format] || :ltsv
  end
end

Instance Method Details

#eachObject



22
23
24
25
26
# File 'lib/nginx_utils/logreader.rb', line 22

def each
  @log.each do |line|
    yield parse(line.chomp)
  end
end