Class: Logging::IO::AMQP
Overview
Send message to an AMQP broker.
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(label, exchange) ⇒ AMQP
constructor
A new instance of AMQP.
- #write(message, routing_key) ⇒ Object
- #write_multiple_messages(formatter, level, messages) ⇒ Object
- #write_single_message(formatter, level, message) ⇒ Object
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(, routing_key) @exchange.publish(, routing_key) end |
#write_multiple_messages(formatter, level, messages) ⇒ Object
122 123 124 |
# File 'lib/logging/io.rb', line 122 def (formatter, level, ) self.write(formatter.(level, self.label, ), "#{self.label}.#{level}") end |
#write_single_message(formatter, level, message) ⇒ Object
118 119 120 |
# File 'lib/logging/io.rb', line 118 def (formatter, level, ) self.write(formatter.(level, self.label, ), "#{self.label}.#{level}") end |