class Fluent::AirbrakeLoggerOutput

Constants

LOG_LEVEL_MAP

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_airbrake_logger.rb, line 54
def initialize
  super
  require 'airbrake'
end

Public Instance Methods

build_error_backtrace(record) click to toggle source
# File lib/fluent/plugin/out_airbrake_logger.rb, line 109
def build_error_backtrace(record)
  record[@batcktrace_record] ? record[@batcktrace_record] : (record['backtrace'] ? record['backtrace'] : ["nil"])
end
build_error_message(record) click to toggle source
# File lib/fluent/plugin/out_airbrake_logger.rb, line 99
def build_error_message(record)
  error_message = record[@error_message_record] ? cut_down_message(record[@error_message_record]) :
    (record['message'] ? cut_down_message(record['message']) : 'Notification')
  "[#{record[@log_level_record]}] #{record[@error_class_record]} #{error_message}"
end
configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_airbrake_logger.rb, line 59
def configure(conf)
  super

  Airbrake.configure do |config|
    config.host    = @host
    config.port    = @port ? @port : (@secure ? 443 : 80)
    config.secure  = @secure
    config.use_system_ssl_cert_chain = @use_system_ssl_cert_chain
    config.http_open_timeout = @http_open_timeout if @http_open_timeout
    config.http_read_timeout = @http_read_timeout if @http_read_timeout
    config.proxy_host        = @proxy_host
    config.proxy_port        = @proxy_port
    config.proxy_user        = @proxy_user
    config.proxy_pass        = @proxy_pass
    config.param_filters     = @param_filters.split(/\s+/) if @param_filters
    config.development_environments = @development_environments.split(/\s+/) if @development_environments
    config.development_lookup = @development_lookup
    config.environment_name   = @environment_name
    config.project_root       = @project_root
    config.notifier_name      = @notifier_name if @notifier_name
    config.notifier_version   = @notifier_version if @notifier_version
    config.notifier_url       = @notifier_url if @notifier_url
    config.user_information   = @user_information if @user_information
    config.user_attribute     = @user_attribute.split(/s+/) if @user_attribute
    config.framework          = @framework if @framework
    config.project_id         = @project_id
    config.logger             = Logger.new(@log_path) unless log_path.nil? || log_path == "nil"
    @aconf = config
  end

  @sender = Airbrake::Sender.new(@aconf)
  @log_level = LOG_LEVEL_MAP[@log_level.upcase]
end
cut_down_message(message) click to toggle source
# File lib/fluent/plugin/out_airbrake_logger.rb, line 105
def cut_down_message(message)
  message.to_s[0, @cut_off_char]
end
emit(tag, es, chain) click to toggle source
# File lib/fluent/plugin/out_airbrake_logger.rb, line 113
def emit(tag, es, chain)
  es.each do |time, record|

    next unless notification_needed(tag, time, record)

    other_record = record.reject {|k, _|
      %W(#{@log_level_record} #{@error_class_record} #{@batcktrace_record}
         #{@error_message_record} #{@component_record} #{@action_record} backtrace).include?(k) }

    @notice  = Airbrake::Notice.new(@aconf.merge(
      :api_key       => @api_key,
      :error_class   => record[@error_class_record],
      :backtrace     => build_error_backtrace(record),
      :error_message => build_error_message(record),
      :hostname      => record['hostname'],
      :component     => record[@component_record],
      :action        => record[@action_record],
      :cgi_data      => other_record
    ))

    @sender.send_to_airbrake(@notice) if @notice
  end
  chain.next
end
notification_needed(_tag, _time, record) click to toggle source
# File lib/fluent/plugin/out_airbrake_logger.rb, line 93
def notification_needed(_tag, _time, record)
  severity_map = LOG_LEVEL_MAP[record[@log_level_record].upcase]

  record[@log_level_record] ? severity_map >= @log_level : false
end