Question: 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)

Answer: 
Creating the logger in `config/environment.rb` should work. I get SQL logging on standard output when I run unit tests if I put the following line in either `config/environment.rb` or `config/environments/test.rb`:

```
ActiveRecord::Base.logger = Logger.new(STDOUT)

```

Does your `MyCustomLogger` class do anything special that causes it to fail during tests? Does it work better if you use `Logger.new(STDOUT)` instead?
In test/test\_helper.rb, before loading config/environment.rb, add:

```
RAILS_DEFAULT_LOGGER = MyCustomLogger.new(STDOUT)

```

Relevant code in railties for 2.3 [railties/lib/initializer.rb#L35](http://github.com/rails/rails/blob/2-3-stable/railties/lib/initializer.rb#L35). Not sure how to do it with Rails 3.0 yet. It looks like you need to call Rails#logger=, but I can't find a good spot for it yet.