Class: Reacter::LoggerAgent

Inherits:
Agent
  • Object
show all
Defined in:
lib/reacter/agents/logger.rb

Instance Attribute Summary

Attributes inherited from Agent

#config, #type

Instance Method Summary collapse

Methods inherited from Agent

create

Constructor Details

#initializeLoggerAgent

Returns a new instance of LoggerAgent.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/reacter/agents/logger.rb', line 8

def initialize()
  super

  case @config.get(:file, 'stdout')
  when 'stderr'
    @stream = STDERR
  when 'stdout'
    @stream = STDOUT
  else
    @stream = File.open(File.expand_path(@config.get(:file)), 'a+')
  end

  @output_format = @config.get(:format)
end

Instance Method Details

#received(message) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/reacter/agents/logger.rb', line 23

def received(message)
  if @output_format.nil?
    line = "logger: [#{message.state or :unknown}] #{message.source}/#{message.metric} = #{message.value}"
  else
    line = Message.dump(message, @output_format)
  end

  @stream.puts(line)
  @stream.flush()

  message
end