Having a level helps

This commit is contained in:
Dan Buch 2012-11-19 22:46:25 -05:00
parent d418a7ae38
commit 19350d73ca

View File

@ -8,6 +8,8 @@ import org.jruby.RubyString
class Sylvilagus::Ch03::LogListeners class Sylvilagus::Ch03::LogListeners
class LogConsumer < DefaultConsumer class LogConsumer < DefaultConsumer
attr_accessor :level
def handleDelivery(consumer_tag, envelope, properties, body) def handleDelivery(consumer_tag, envelope, properties, body)
body_string = RubyString.bytes_to_string(body) body_string = RubyString.bytes_to_string(body)
puts "#{level}: #{body_string}" puts "#{level}: #{body_string}"
@ -45,8 +47,11 @@ class Sylvilagus::Ch03::LogListeners
channel.queue_bind(info_queue, 'amq.rabbitmq.log', 'info') channel.queue_bind(info_queue, 'amq.rabbitmq.log', 'info')
errors_consumer = LogConsumer.new(channel) errors_consumer = LogConsumer.new(channel)
errors_consumer.level = 'error'
warnings_consumer = LogConsumer.new(channel) warnings_consumer = LogConsumer.new(channel)
warnings_consumer.level = 'warning'
info_consumer = LogConsumer.new(channel) info_consumer = LogConsumer.new(channel)
info_consumer.level = 'info'
puts 'Setting up consumers...' puts 'Setting up consumers...'
channel.basic_consume(errors_queue, false, errors_consumer) channel.basic_consume(errors_queue, false, errors_consumer)