Class: Kafo::PuppetLogParser

Inherits:
Object
  • Object
show all
Defined in:
lib/kafo/puppet_log_parser.rb

Instance Method Summary collapse

Constructor Details

#initializePuppetLogParser

Returns a new instance of PuppetLogParser.



3
4
5
# File 'lib/kafo/puppet_log_parser.rb', line 3

def initialize
  @last_level = nil
end

Instance Method Details

#parse(line) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/kafo/puppet_log_parser.rb', line 7

def parse(line)
  method, message = case
                      when line =~ /^Error:(.*)/i || line =~ /^Err:(.*)/i
                        [:error, $1]
                      when line =~ /^Warning:(.*)/i || line =~ /^Notice:(.*)/i
                        [:warn, $1]
                      when line =~ /^Info:(.*)/i
                        [:info, $1]
                      when line =~ /^Debug:(.*)/i
                        [:debug, $1]
                      else
                        [@last_level.nil? ? :info : @last_level, line]
                    end

  @last_level = method
  return [method, message.chomp]
end