views:

409

answers:

2

I'm trying to figure out the best way to do error logging in rails using a database (in this case MySQL) as a backend.

It looks like the two popular logging frameworks within rails are the built-in Logger framework and Log4r.

However, as far as I can tell, neither of these support database logging to a database without writing some custom code (which may or may not be easy -- I just don't want to start down that path if there's already a well-understood solution).

I also found Exception_Logger, but this seems to catch any unhandled exceptions and would more-than-likely be used to augment explicit logging.

+1  A: 

Exception Logger logs the exceptions you don't handle. If this is what you want, I'd just use hoptoad (http://hoptoadapp.com) as it does a very good job of it.

If you mostly want to log exceptions that you handle, you can create your own database model and use it to call a function from your exception handler that will write it to the database. Logging handled exceptions implicitly would be either impossible or ill-advised as it would require messing around significantly with how you put your exception handlers in place (because once you rescue, it stops propagating up the call chain, so you would have to inject something into the call chain before the handler rescue).

Ben Hughes
A: 

you could use syslog-ng, it's very flexible, and can be connected to rails.

connecting rails to syslog-ng: unified rails logging with syslog ng

making syslog-ng use a mysql db backend: Centralized syslog-ng to Mysql

Maximiliano Guzman