Module: MailyHerald::Logging::LoggerExtensions

Defined in:
lib/maily_herald/logging.rb

Instance Method Summary collapse

Instance Method Details

#log_processing(*args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/maily_herald/logging.rb', line 13

def log_processing *args
  options = args.extract_options!
  mailing, entity, mail = nil
  args.each do |arg|
    case arg
    when Mailing
      mailing = arg
    when ::Mail::Message
      mail = arg
    else
      entity = arg
    end
  end
  prefix = options.delete(:prefix)
  level = options.delete(:level) || :info

  log_msg = []
  if entity.is_a?(Hash)
    log_msg << "<#{entity[:class]}##{entity[:id]}> #{mail.try(:to)}" if entity
  else
    log_msg << "<#{entity.try(:class).try(:name)}##{entity.try(:id)}> #{entity} #{mail.try(:to)}" if entity
  end
  log_msg << "<#{mailing.try(:class).try(:name)}##{mailing.try(:id)}> #{mailing}" if mailing

  send(level, [prefix, log_msg.join(", ")].compact.join(": "))
end