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
24
25
26
27
28
29
# 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 =~ /^Notice:(.*)/i
                        [:info, $1]
                      when line =~ /^Warning:(.*)/i || line =~ /^Debug:(.*)/i || line =~ /^Info:(.*)/i
                        [:debug, $1]
                      else
                        [@last_level.nil? ? :info : @last_level, line]
                    end

  if message.include?('Loading facts') && method != :error
    method = :debug
  end

  if message.include?('Applying configuration version')
    method = :debug
  end

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