Log your SQL in Rails application inside unit test

Posted by Phuong Nguy?n on Stack Overflow See other posts from Stack Overflow or by Phuong Nguy?n
Published on 2010-06-11T11:26:04Z Indexed on 2010/06/11 11:32 UTC
Read the original article Hit count: 168

I want to install a logger so that I can dump all executed SQL of my rails application. Problem is, such logger is associated with AbstractAdapter which initialized very soon under test mode, and thus cannot be set by my initializer code. I try to put

ActiveRecord::Base.logger = MyCustomLogger.new(STDOUT) 

in the end of environment.rb like someone advised but it only works when being run in console environment (kicked by script/console), not when run under test mode. I wonder if there is any way to config such logger so that I will sure to be invoked under any environment (test, development, production, console)

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about logging