> ## Content Index
> Fetch the complete content index at: https://til.codes/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to turn on SQL debug logging for ActiveRecord
- URL: https://til.codes/how-to-turn-on-sql-debug-logging-for-activerecord/
- Published: 2016-09-07T06:23:00.000Z
- Updated: 2016-09-09T06:33:43.000Z
- Author: Manu Ajith
- Tags: rails, postgresql, SQL, #Import 2024-07-13 21:01

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](http://guides.rubyonrails.org/debugging%5Frails%5Fapplications.html?ref=til.codes) about debugging
- ActiveRecord logger [class](http://apidock.com/rails/ActiveRecord/Base/logger/class?ref=til.codes)