Class: AMQPLogging::LogDevice

Inherits:
Object
  • Object
show all
Defined in:
lib/amqp_logging/log_device.rb

Constant Summary collapse

RETRY_AFTER =
10.seconds

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ LogDevice

Returns a new instance of LogDevice.



7
8
9
# File 'lib/amqp_logging/log_device.rb', line 7

def initialize(opts = {})
  @configuration = opts
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



4
5
6
# File 'lib/amqp_logging/log_device.rb', line 4

def configuration
  @configuration
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/amqp_logging/log_device.rb', line 5

def logger
  @logger
end

Instance Method Details

#closeObject



23
24
25
# File 'lib/amqp_logging/log_device.rb', line 23

def close
  reset_amqp # TODO: Test!
end

#write(msg) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/amqp_logging/log_device.rb', line 11

def write(msg)
  begin
    if !@paused || @paused <= RETRY_AFTER.ago
      routing_key = configuration[:routing_key].respond_to?(:call) ? configuration[:routing_key].call(msg).to_s : configuration[:routing_key]
      exchange.publish(msg, :key => routing_key)
    end
  rescue Exception => exception
    reraise_expectation_errors!
    pause_amqp_logging(exception)
  end
end