Created
November 30, 2011 18:16
-
-
Save j-manu/1410106 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 logging methods | |
# very useful for digging into | |
# queries | |
require 'logger' | |
require 'activerecord' if rails?(2) | |
require 'hirb' | |
Hirb.enable | |
def enable_logger | |
log_to(Logger.new(STDOUT)) | |
end | |
def disable_logger | |
log_to(nil) | |
end | |
def log_to(logger) | |
ActiveRecord::Base.logger = logger | |
ActiveRecord::Base.clear_active_connections! | |
end | |
def execute(query) | |
ActiveRecord::Base.connection.execute(query) | |
end | |
def l(filename) | |
if rails?(2) | |
load RAILS_ROOT + '/tmp/' + "#{filename}.rb" | |
else | |
load Rails.root.join("tmp/#{filename}.rb") | |
end | |
end | |
# logging into console by default | |
enable_logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment