Class: FFWD::Plugin::Log::Writer

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/ffwd/plugin/log/writer.rb

Instance Method Summary collapse

Methods included from Logging

included, #log

Constructor Details

#initialize(core, prefix) ⇒ Writer

Returns a new instance of Writer.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ffwd/plugin/log/writer.rb', line 24

def initialize core, prefix
  @p = prefix ? "#{prefix} " : ""

  subs = []

  core.output.starting do
    log.info "Started (prefix: '#{@p}')"

    subs << core.output.event_subscribe do |e|
      log.info "Event: #{@p}#{JSON.dump(e.to_h)}"
    end

    subs << core.output.metric_subscribe do |m|
      log.info "Metric: #{@p}#{JSON.dump(m.to_h)}"
    end
  end

  core.output.stopping do
    log.info "Stopped"

    subs.each(&:unsubscribe).clear
  end
end