Class: Stenotype::Adapters::StdoutAdapter

Inherits:
Base
  • Object
show all
Defined in:
lib/stenotype/adapters/stdout_adapter.rb

Overview

An adapter implementing method #publish to send data to STDOUT

Examples:

class SomeClassWithEvents
  def method_emitting_enent
    result_of_calculations = collect_some_data
    # This will print the data to STDOUT by default
    stdout_adapter.publish(result_of_calculation, additional: :data, more: :data)
    result_of_calculations
  end

  def stdout_adapter
    Stenotype::Adapters::StdoutAdapter.new
  end
end

Instance Method Summary collapse

Methods inherited from Base

#auto_initialize!, #initialize

Constructor Details

This class inherits a constructor from Stenotype::Adapters::Base

Instance Method Details

#flush!Object

Does nothing



43
44
45
# File 'lib/stenotype/adapters/stdout_adapter.rb', line 43

def flush!
  # noop
end

#publish(event_data, **additional_attrs) ⇒ Object

Examples:

Publishing to default client (STDOUT)

adapter = Stenotype::Adapters::StdoutAdapter.new
adapter.publish({ event: :data }, { additional: :data })

Publishing to custom client (STDERR)

adapter = Stenotype::Adapters::StdoutAdapter.new(client: STDERR)
adapter.publish({ event: :data }, { additional: :data })

Parameters:

  • event_data (Sting)

    The data to be published to STDOUT



34
35
36
37
38
# File 'lib/stenotype/adapters/stdout_adapter.rb', line 34

def publish(event_data, **additional_attrs)
  client.info("[Stenotype::Event] emitted with the following attributes") do
    "MESSAGE BODY: #{event_data}, MESSAGE ATTRIBUTES #{additional_attrs.to_json}"
  end
end