class Fluent::WinEvtLog::PositionFile

Public Class Methods

new(file, map, last_pos) click to toggle source
# File lib/fluent/plugin/in_winevtlog.rb, line 216
def initialize(file, map, last_pos)
  @file = file
  @map = map
  @last_pos = last_pos
end
parse(file) click to toggle source

parsing file and rebuild mysself

# File lib/fluent/plugin/in_winevtlog.rb, line 236
def self.parse(file)
  map = {}
  file.pos = 0
  file.each_line {|line|
    # check and get a matched line as m
    m = /^([^\t]+)\t([0-9a-fA-F]+)\t([0-9a-fA-F]+)/.match(line)
    next unless m
    ch = m[1] 
    pos = m[2].to_i(16)
    seek = file.pos - line.bytesize + ch.bytesize + 1
    map[ch] = FilePositionEntry.new(file, seek)
  }
  new(file, map, file.pos)
end

Public Instance Methods

[](ch) click to toggle source
# File lib/fluent/plugin/in_winevtlog.rb, line 222
def [](ch)
  if m = @map[ch]
    return m
  end
  @file.pos = @last_pos
  @file.write ch
  @file.write "\t"
  seek = @file.pos
  @file.write "00000000\t00000000\n"
  @last_pos = @file.pos
  @map[ch] = FilePositionEntry.new(@file, seek)
end