Class: AtomLog::Parser
- Inherits:
-
Object
- Object
- AtomLog::Parser
- Defined in:
- lib/parser.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(log, lines = nil) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(log, lines = nil) ⇒ Parser
Returns a new instance of Parser.
6 7 8 9 |
# File 'lib/parser.rb', line 6 def initialize(log, lines = nil) @lines = lines || 10 @log = log end |
Class Method Details
.parse_log_line(l) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/parser.rb', line 11 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 |
Instance Method Details
#parse ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/parser.rb', line 26 def parse arr = [] log = File::Tail::Logfile.open(@log, :return_if_eof => true, :backward => @lines) log.tail(@lines) do |line| arr << AtomLog::Parser.parse_log_line(line) end arr end |