class Rusen::Notifiers::Log4rNotifier

Public Class Methods

identification_symbol() click to toggle source
# File lib/rusen/notifiers/log4r_notifier.rb, line 19
def self.identification_symbol
  :log4r
end
new(settings) click to toggle source
Calls superclass method Rusen::Notifiers::BaseNotifier::new
# File lib/rusen/notifiers/log4r_notifier.rb, line 23
def initialize(settings)
  super(settings)

  load_config(@settings.log4r_config_file)

  @logger = logger_instance(@settings.logger_name)
end

Public Instance Methods

notify(notification) click to toggle source
# File lib/rusen/notifiers/log4r_notifier.rb, line 31
def notify(notification)
  @notification = notification
  @sessions     = get_sessions(@notification)

  # We need to ignore all the exceptions thrown by Log4rNotifier#notify.
  @logger.error { build_content }
rescue Exception => exception
  handle_notification_exception(exception)
end

Private Instance Methods

build_content() click to toggle source
# File lib/rusen/notifiers/log4r_notifier.rb, line 43
def build_content
  template_path = File.expand_path('../../templates/log4r_template.txt.erb', __FILE__)

  template = File.open(template_path).read
  rhtml = ERB.new(template, nil, '-')
  rhtml.result(binding)
end
load_config(config_yml) click to toggle source

Loads the given config file.

@param [String] config_yml Configuration file path.

# File lib/rusen/notifiers/log4r_notifier.rb, line 62
def load_config(config_yml)
  if config_yml
    Log4r::YamlConfigurator.load_yaml_file(config_yml)
  end
end
logger_instance(name = nil) click to toggle source
# File lib/rusen/notifiers/log4r_notifier.rb, line 51
def logger_instance(name = nil)
  if name
    Log4r::Logger[name]
  else
    Log4r::Logger.root
  end
end