13

The default Ruby Sequel behaviour is to log all DB queries at the INFO level (unlike ActiveRecord which logs at the DEBUG level). How do I change this?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
NatGordon
  • 956
  • 2
  • 10
  • 17

1 Answers1

24

Previously, it was fairly simple to do with a proxy logger object, but enough people have asked for this that I implemented it. With the git master branch of Sequel, you can now do:

DB.sql_log_level = :debug

Which will use the debug method instead of the info method when logging queries.

Jeremy Evans
  • 11,959
  • 27
  • 26
  • 2
    Probably in an initializer. It does depend on the Sequel::Database object being in DB, which may not be true if you are not loading it yourself. A safer bet is:Sequel::DATABASES.each{|d| d.sql_log_level = :debug} – Jeremy Evans Oct 06 '10 at 20:12
  • Hi Jeremy, that answer was from 2010. I just tried it (`DB.sql_log_level = :debug`) and no debugging output at all. What is the currently working method? (Would be especially nice to see that here, since this is the first hit on Google...) – Sixtyfive Jun 24 '20 at 21:11
  • 4
    @Sixtyfive Make sure you supply a logger to the database: `require 'sequel'; require 'logger'; DB = Sequel.sqlite; DB.loggers << Logger.new($stdout); DB['select 1'].to_a` => `I, [2020-07-03T18:28:33.321470 #262544] INFO -- : (0.000376s) select 1` – ZimbiX Jul 03 '20 at 08:33