How do I set Ruby Sequel logging to the DEBUG level?
Asked Answered
V

1

14

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?

Vinous answered 5/10, 2010 at 17:40 Comment(0)
K
25

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.

Kilo answered 5/10, 2010 at 18:36 Comment(3)
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}Kilo
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...)Diagnose
@Diagnose 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 1Shower

© 2022 - 2024 — McMap. All rights reserved.