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.
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
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.
-
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)
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
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.
Bug reports and pull requests are welcome on GitHub at https://github.com/fursich/exception_file_notifier.
All the folks who have given supports, especially @motchang and @katsurak for great advises and reviews.
The gem is available as open source under the terms of the MIT License.