This project is archived and is in readonly mode.
SQL Display
Reported by Ryan Bigg | June 13th, 2009 @ 11:18 AM | in 2.x
I wrote a plugin called SQL Display http://github.com/radar/sql_display/tree/master a couple of days ago and since showing it off to some people, they've suggested that this should be in Rails core as it's helpful for debugging purposes. Admittedly, the code isn't "beautiful" and I'm sure someone can figure out a better way than I've done it but... I don't want to go into the effort of writing a patch for this and having it bounced. So who else thinks having this functionality in Rails is a good idea?
Comments and changes to this ticket
-
David Knorr June 13th, 2009 @ 12:33 PM
+1 However, I agree with you that it probably would be better to use a less hack-ish attempt. I don't know exactly how you'd implement this, but something like setting an instance variable in the sql method and then checking if it's true in whatever method in ActiveRecord that takes care of performing SQL queries, would be cool.
-
Morten June 13th, 2009 @ 06:24 PM
Rails.logger.silence(Logger::DEBUG) do
Account.count endThe block returns the last statement of the block, which is expected behavior (or more intuitive at least). You get the SQL printed in your .log file, regardless of environment.
To be desired would be nicer semantics on setting the log level for Rails.logger eg. at_level(level = Logger::INFO), and reimplement "silence" to call that with Logger::ERROR instead.
-
Ryan Bigg June 14th, 2009 @ 10:08 AM
Morten,
Your code does not do what you say it does, for me it prints out the output of the count rather than the SQL.
I've hacked some more today on sql_display and now I'm overriding methods in ActiveRecord in the plugin. I revoke my idea of putting this plugin into core, since it will involve too many if statements.
-
Pratik June 14th, 2009 @ 11:20 AM
- State changed from new to wontfix
This should be in mailing list really. I just use 3 lines in my ~/.irbrc for this :
def log_to(stream=$stdout) ActiveRecord::Base.logger = Logger.new(stream) ActiveRecord::Base.connection_pool.clear_reloadable_connections! end
-
Morten June 14th, 2009 @ 01:33 PM
Ryan, I suppose I misunderstood your intention. You want the SQL in hand, I want to be able to log it regardless of environment.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>