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 minutesparser = RailsLogParser::Parser.from_journalctl(unit: "myapp.service", since: "1 hour ago")
print parser.summary(last_minutes: 22) # print summary for the last 22 minutesYou can configure filters:
# config/rails_log_parser.rb
RailsLogParser.configure do |parser|
parser.ignore_lines = [
/Error performing MailerConfigurationJob .+ Net::ReadTimeout/,
]
endChangelog
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.