Created
July 16, 2010 16:05
-
-
Save pvdb/478547 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# ActiveRecord SQL Logging on the Rails Console - revisited/updated | |
# ----------------------------------------------------------------- | |
# | |
# If you're living on the edge ("edge Rails", that is) and would like to | |
# log all SQL statements executed by ActiveRecord to STDOUT when you're | |
# in a Rails console, then the ConsoleLogSubscriber class is for you! | |
# | |
# Notes: | |
# | |
# (1) integration into ".irbrc" left as an exercise to the reader | |
# (2) at present (2010-07-16) this is only compatible with edge Rails | |
# (3) but I expect this will work in the next Rails 3.0 beta or RC release | |
# (4) this replaces the MultiLogger class: http://gist.github.com/478307 | |
# | |
module ActiveRecord | |
class ConsoleLogSubscriber < ActiveRecord::LogSubscriber | |
def initialize | |
@logger = Logger.new(STDOUT) | |
super | |
end | |
def sql(event) | |
super | |
end | |
def logger | |
@logger | |
end | |
end | |
end | |
ActiveRecord::ConsoleLogSubscriber.attach_to :active_record |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ad note (4): this replaces the
MultiLogger
classFor older versions of Rails 3.0 (ie. "3.0.0.beta4" and before) which don't implement the
LogSubscriber
class, theMultiLogger
class can be used instead:http://gist.github.com/478307
Lemme know how you get on using these two classes,
ActiveSupport::MultiLogger
andActiveRecord::ConsoleLogSubscriber
... happy logging! :-)