Class: RabbitHutch::Log4rConsumer

Inherits:
Object
  • Object
show all
Defined in:
lib/consumers/log4r_consumer.rb

Instance Method Summary collapse

Constructor Details

#initialize(rabbitmq_host, config) ⇒ Log4rConsumer

Returns a new instance of Log4rConsumer.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/consumers/log4r_consumer.rb', line 9

def initialize(rabbitmq_host, config)
  puts "\tInitializing Log4r Consumer"
  @rabbitmq_host = rabbitmq_host
  @config = config
  @log_name = rabbitmq_host["displayname"]
  @config.consumers.each do |consumer|
    if consumer["name"] == 'log4r_consumer'
      @log_prefix = consumer['log_prefix']
      @log_location = consumer['log_location']
    end
  end
  
  
  @logger = Log4r::Logger.new("#{@log_name}#_log")
  @logger.outputters << Log4r::FileOutputter.new("#{@log_name}_filelog", :filename =>  "#{@log_location}/#{@log_prefix}#{@log_name}.log")
end

Instance Method Details

#log_event(item) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/consumers/log4r_consumer.rb', line 26

def log_event(item)
  begin  
    @logger.info(item)    
  rescue Exception => e
    puts "Error occurred Message Handler trying to write messages to Log #{e.inspect}" 
    #@log.error("Error occurred Message Handler trying to write messages to MONGODB #{e.inspect}") 
  end
end