No commit activity in last 3 years
No release in over 3 years
Exception File Notifier records exception logs in JSON format, helping you track errors in the production environment.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 10.0
>= 3.0

Runtime

 Project Readme

Exception File Notifier

Gem Version Travis MIT License

Exception File Notifier is a custom notifier for Exception Notification, that records notifications onto a log file when errors occur in a Rack/Rails application.

All the error logs are converted into JSON format. This would be useful typically when you wish to monitor an app with monitoring tools - e.g. Kibana + ElasticSearch + Fluentd, or anything alike.

Installation

Add this line to your application's Gemfile:

gem 'exception_file_notifier'

And then execute:

$ bundle

Or install it yourself as:

$ gem install exception_file_notifier

Usage

Set proper configs in config/initializers/exception_notification.rb

To get started, use the simplest settings:

ExceptionNotification.configure do |config|

  config.add_notifier :file, {
      filename:  "#{Rails.root}/log/exceptions.log"
  }

That works in all the environment (including test).

You could also customize settings like so:

ExceptionNotification.configure do |config|

# disable all the notifiers in certain environment
  config.ignore_if do |exception, options|
    Rails.env.test?
  end

  config.add_notifier :file, {
      filename:  "#{Rails.root}/log/exceptions_#{Rails.env}.log",  # generate different log files depending on environments
      shift_age: 'daily'     # use shift_age/shift_size options to rotate log files
  }

You could also pass as many original values as you like, which will be evaluated JSON-ified at the time when an exception occurs. For detailed setting you may wish to consult with the Exception Notification original readme.

available options:

  • filename: specify the log file (preferablly with its absolute path)

  • shift_age: option for log file rotation: directly passed to Ruby Logger

  • shift_size: option for log file rotation: directly passed to Ruby Logger

(for the latter options see also: https://docs.ruby-lang.org/ja/latest/method/Logger/s/new.html)

Note

Due to a bug with ruby Logger discovered in ruby 2.2 - 2.3, it might happen that you cannot rotate logs by using shift_age. (for those who come up with any workaround for this, please let us know / PR are welcomed)

Meanwhile you could cope with either 1) upgrading your ruby version upto 2.4, or 2) rotate logs by size, not date

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/fursich/exception_file_notifier.

Special Thanks To

All the folks who have given supports, especially @motchang and @katsurak for great advises and reviews.

License

The gem is available as open source under the terms of the MIT License.