log4r-exceptionable

This gem provides failure handlers for Resque and Rack that logs all failures using log4r. It is expected that these logs will get sent elsewhere (e.g. graylog) by using log4r outputters (e.g. log4r-gelf). It adds contextual information to the log message using Log4r::MDC, which is useful if you are using log4r-gelf since it sends all of those to graylog as custom attributes.

Build Status

Install

gem install log4r-exceptionable

or add to your Gemfile

To use

Add to some initializer code:

Log4rExceptionable::Configuration.configure do |config|

  # The default loggers used when a source logger is not available
  # required (at least one logger needs to be set, but you don't need
  # to set rack if using resque, and vice versa)
  #
  config.rack_failure_logger = "rails::SomeRackLogger"
  config.resque_failure_logger = "rails::SomeResqueLogger"

  # Prevent the detection and use of the source class's logger
  # The source logger is taken from the resque class raising
  # the exception, rails controller raising the exception,
  # or rack_env['rack.logger']
  # optional - defaults to true
  #
  # config.use_source_logger = false

  # Log at the given log level
  # optional - defaults to :fatal
  #
  # config.log_level = :error

  # A whitelist of the context keys to include when logging.
  # If this is set, _only_these keys will show up.
  # optional - defaults to nil, so all keys get included
  #
  # config.context_inclusions = ['rack_env.rack.version']

  # A blacklist of the context keys to exclude when logging.
  # If this is set, the keys in here will not show up.
  # optional - defaults to nil, so no keys get excluded
  #
  # config.context_exclusions = ['resque_args']

end

Rails.application.config.middleware.use Log4rExceptionable::RackFailureHandler
Resque::Failure.backend = Log4rExceptionable::ResqueFailureHandler

All failures will be logged using the source logger or the given logger if a source is not available. The logger can be set using their log4r fullname or a log4r logger instance.

Author

Matt Conway :: [email protected] :: @mattconway

Copyright (c) 2012 Matt Conway. See LICENSE for details.