How to turn on SQL debug logging for ActiveRecord

If you want to see the SQL queries that your apps are running and want o optimize them or tune them, then it is a nice idea to log them.

You can either log it to your log file or even to STDOUT.

You can set the log level in your environment file to debug so that you can get maximum data out of your application and can use the same for tuning.

config.log_level = :debug  

To log it to STDOUT, you can add the following snippet to your specific environment file.

ActiveRecord::Base.logger = Logger.new(STDOUT)  

References:

  • Rails Guide about debugging
  • ActiveRecord logger class
comments powered by Disqus