Class: Logging::IO::AMQP

Inherits:
Base
  • Object
show all
Defined in:
lib/logging/io.rb

Overview

Send message to an AMQP broker.

Instance Attribute Summary

Attributes inherited from Base

#label

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, exchange) ⇒ AMQP

Returns a new instance of AMQP.



114
115
116
# File 'lib/logging/io.rb', line 114

def initialize(label, exchange)
  @label, @exchange = label, exchange
end

Class Method Details

.bootstrap(config) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/logging/io.rb', line 100

def self.bootstrap(config)
  require 'amq/client'

  AMQ::Client.connect(config) do |connection|
    channel = AMQ::Client::Channel.new(connection, 1)

    channel.open

    exchange = AMQ::Client::Exchange.new(connection, channel, 'amq.topic', :topic)

    self.new(exchange)
  end
end

Instance Method Details

#write(message, routing_key) ⇒ Object



126
127
128
# File 'lib/logging/io.rb', line 126

def write(message, routing_key)
  @exchange.publish(message, routing_key)
end

#write_multiple_messages(formatter, level, messages) ⇒ Object



122
123
124
# File 'lib/logging/io.rb', line 122

def write_multiple_messages(formatter, level, messages)
  self.write(formatter.format_multiple_messages(level, self.label, messages), "#{self.label}.#{level}")
end

#write_single_message(formatter, level, message) ⇒ Object



118
119
120
# File 'lib/logging/io.rb', line 118

def write_single_message(formatter, level, message)
  self.write(formatter.format_single_message(level, self.label, message), "#{self.label}.#{level}")
end