Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

Is there a way to disable SQL query logging when I'm executing commands in the console? Ideally, it would be great if I can just disable it and re-enable it with a command in the console.

I'm trying to debug something and using "puts" to print out some relevant data. However, the sql query output is making it hard to read.

Edit: I found another solution, since setting the logger to nil sometimes raised an error, if something other than my code tried to call logger.warn

Instead of setting the logger to nil you can set the level of the logger to 1.

ActiveRecord::Base.logger.level = 1 # or Logger::INFO

1 Answer

0 votes
by (40.7k points)

To turn off you can use this code:

old_logger = ActiveRecord::Base.logger

ActiveRecord::Base.logger = nil

To turn it back on you can use this code:

ActiveRecord::Base.logger = old_logger

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 9, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...