Module: QdLogger

Defined in:
lib/queue_dispatcher/qd_logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



2
3
4
# File 'lib/queue_dispatcher/qd_logger.rb', line 2

def logger
  @logger
end

Instance Method Details

#initialize_logger(logger = nil) ⇒ Object



4
5
6
# File 'lib/queue_dispatcher/qd_logger.rb', line 4

def initialize_logger(logger = nil)
  @logger = logger || Logger.new("#{File.expand_path(Rails.root)}/log/queue_dispatcher.log")
end

#log(args = {}) ⇒ Object

Write a standart log message



9
10
11
12
13
14
# File 'lib/queue_dispatcher/qd_logger.rb', line 9

def log(args = {})
  sev = args[:sev] || :info
  msg = Time.now.to_s + " #{sev.to_s.upcase} #{$$} (#{self.class.name}): " + args[:msg]
  logger.send(sev, msg) if logger
  puts "#{sev.to_s.upcase}: #{args[:msg]}" if logger.nil? || args[:print_log]
end