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
# File 'lib/nginx_utils/logreader.rb', line 7

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

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

Instance Method Details

#eachObject



19
20
21
22
23
# File 'lib/nginx_utils/logreader.rb', line 19

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