lib/halog/log_parser.rb
# parses the io stream yielding each valid LogEntry that is encountered.  Invalid lines
# are logged to stderr
parses the io stream yielding each valid LogEntry that is encountered.  Invalid lines
are logged to stderr
parses the io stream yielding each valid LogEntry that is encountered . Invalid lines are logged to stderr
def parse(io,options = {})
      io = advance_io(io,options)
      @starting_offset = io.pos
      total_bytes      = io.stat.size - @starting_offset
      @start_time       = Time.now
      $stderr.puts
      $stderr.puts status_header
      io.each do |line|
        @byte_count += line.size
        if @entry_count % SAMPLE_EVERY == 0 then
          before_parse = Time.now
          entry = LogEntry.parse(line) 
          @parse_time += ( (Time.now - before_parse) * SAMPLE_EVERY )
        else
          entry = LogEntry.parse(line) 
        end
        if entry then
          @first_entry_time ||= entry.time
          @last_entry_time = entry.time
          @entry_count += 1  
          yield entry if block_given?
        else
          @error_count += 1
          $stderr.puts 
          $stderr.puts "Failure to parse line : #{line.rstrip}"
        end
        if @entry_count % REPORT_EVERY == 0 then 
          $stderr.print "#{status_output(io.pos,total_bytes)}\r"
        end
      end 
      $stderr.puts status_output(io.pos,total_bytes)
      $stderr.puts
      return self
    end
def parse ( io , options = { } ) io = advance_io ( io , options ) @starting_offset = io . pos total_bytes = io . stat . size - @starting_offset @start_time = Time . now $stderr . puts $stderr . puts status_header io . each do | line | @byte_count += line . size if @entry_count % SAMPLE_EVERY == 0 then before_parse = Time . now entry = LogEntry . parse ( line ) @parse_time += ( ( Time . now - before_parse ) * SAMPLE_EVERY ) else entry = LogEntry . parse ( line ) end if entry then @first_entry_time ||= entry . time @last_entry_time = entry . time @entry_count += 1 yield entry if block_given? else @error_count += 1 $stderr . puts $stderr . puts "Failure to parse line : #{line.rstrip}" end if @entry_count % REPORT_EVERY == 0 then $stderr . print "#{status_output(io.pos,total_bytes)}\r" end end $stderr . puts status_output ( io . pos , total_bytes ) $stderr . puts return self end
parses the io stream yielding each valid LogEntry that is encountered.
parses the io stream yielding each valid LogEntry that is encountered .
# sample the time it takes every N rows # io.each
io
options