Sha256: 654e6c534cb6002677e1bca2b6ea1d2d5352dd643942b91392188e7380d78b00

Contents?: true

Size: 795 Bytes

Versions: 4

Compression:

Stored size: 795 Bytes

Contents

module AtomLog

  class LogFile < File
    include File::Tail
  end


  class Parser

    def initialize(log, lines = nil)
      @lines = lines || 10
      @log = log
    end

    def self.parse_log_line(l)
      res = {}
      line = l.split('[')[1].to_s.split(']')
      middle = line[0].to_s.split
      pid = middle.pop
      date = middle
      severity,msg = line[1].to_s.split('--')
      res[:date] = date.join(' ')
      res[:severity_id] = l.split[0].to_s.gsub(',','')
      res[:pid] = pid.to_s.gsub('#','')
      res[:severity] = severity.to_s.gsub(' ','')
      res[:msg] = msg
      res
    end

    def parse
      arr = []
      log = LogFile.new(@log)
      log.tail(@lines) do |line|
        arr << AtomLog::Parser.parse_log_line(line)
      end
      arr
    end

  end


end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jcapote-atomlog-1.0.2 lib/parser.rb
jcapote-atomlog-1.0.3 lib/parser.rb
jcapote-atomlog-1.0.4 lib/parser.rb
jcapote-atomlog-1.1.0 lib/parser.rb