简体   繁体   中英

Rails - logging server errors to DB

If I get 500 errors in my server logs, I would prefer to store them to the DB in a table like server_errors (id, user_id, created_at, build_version, error_code, error_output).

My initial idea is to just run a script that constantly greps log/production.log for errors and stores them to the DB as they come in, but this seems like an ugly solution and gets unwieldy when you consider things like log rotation etc.

This seems like a common enough feature that there should be a gem for it, or some standard functionality built into Rails (2.3.12) so I was hoping that somebody might know of something like that. Or could suggest a better methodology if you can think of one.

Most folks use exception_notification , NewRelic RPM , or AirBrake (formerly known as Hoptoad) to see their exceptions.

If you would like to roll your own, take a look at how exception_notification does it . It uses a middleware component to catch the exceptions. You could catch the exceptions in your own custom middleware, then save the information to the database table you described above instead of emailing it.

For background queueing, see how resque does it .

If you're using Rails 2.3, you should use the 2-3-stable branch of exception_notification instead of the master branch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM