/ rails

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)


  • Rails Guide about debugging
  • ActiveRecord logger class
Manu S Ajith

Manu S Ajith

Tech Entrepreneur, dating Elixir, in long-term ❤️ w/ Ruby, had multiple one night stands w/ Go. Into functional paradigms DDD/CQRS/EventSourcing architecture these days. @manusajith on the interwebs

Read More