Low commit activity in last 3 years
If you want to get an email with errors and fatal log lines you can use this gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 7.0, < 9
 Project Readme

RailsLogParser

This gem helps you to quick analyse your server logs without external monitor servers. Simple applications with a low number of requests cause only a low number of errors. So you can call a cronjob to analyse your logs periodly. If the summary is not empty your server will email you the result automaticly.

Requirements

  • Ruby 3.2 or newer
  • ActiveSupport 7.0 or newer

Installation

Add this line to your application's Gemfile:

gem 'rails_log_parser'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install rails_log_parser

Usage

Sets your server log path:

RailsLogParser::Parser.log_path = Rails.root.join('log/production.log')

Call the rake tasks in cronjobs:

LOG_PATH=/srv/rails/log/production.log
0,20,40 * * * * rake rails_log_parser:parse[22]      # summary of the last 22 minutes

Or use it in your code:

parser = RailsLogParser::Parser.from_file(log_path)
puts parser.actions.select(&:fatal?).map(&:headline)
parser = RailsLogParser::Parser.from_file(log_path)
print parser.summary(last_minutes: 22)          # print summary for the last 22 minutes
parser = RailsLogParser::Parser.from_journalctl(unit: "myapp.service", since: "1 hour ago")
print parser.summary(last_minutes: 22)          # print summary for the last 22 minutes

You can configure filters:

# config/rails_log_parser.rb

RailsLogParser.configure do |parser|
  parser.ignore_lines = [
    /Error performing MailerConfigurationJob .+ Net::ReadTimeout/,
  ]
end

Changelog

See CHANGELOG.md.

Contributing

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

License

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