This project is archived and is in readonly mode.
SQL Display
-
Bodaniel Jeanes
+1
I've wanted this for a while...
-
mark (at aussiev8.com)
+1 i was just about to make a similar plugin.
-
mib_s2d5o9
+1 this would make my life convenient - add to Core
-
David Knorr
+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
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
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
- 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
Ryan, I suppose I misunderstood your intention. You want the SQL in hand, I want to be able to log it regardless of environment.