Log every SQL query to database in Rails

logging, ruby, ruby-on-rails, sql

Solution

SQL logging in rails - In brief - you need to override ActiveRecord execute method. There you can add any logic for logging.

Problem

I want to save to a log file some SQL query rails performs, (namely the CREATE, UPDATE and DELETE ones) therefore I need to intercept all queries and then filter them maybe with some regexp and log them as needed. Where would I put such a thing in the rails code?

Original source

Related problems