This project is archived and is in readonly mode.

#4816 ✓resolved
Doug Daniels

Setting ActiveRecord::Base.logger is not effective

Reported by Doug Daniels | June 10th, 2010 @ 02:15 AM | in 3.0.2

I'm trying to use ActiveRecord outside of Rails, and setting the ActiveRecord::Base.logger doesn't seem to work. I think it has something to do with the Rails LogSubscriber being used to print out log messages from ActiveRecord now, and that LogSubscriber being hardcoded to Rails.logger.

Here's the code:

require 'rubygems'
require 'logger'

logger = Logger.new(STDOUT)
logger.level = Logger::DEBUG

require 'active_record'
ActiveRecord::Base.logger = logger

pool = ActiveRecord::Base.establish_connection(
  :adapter => 'postgresql',
  :database => 'mortar_development',
  :pool => 5,
  :username => 'postgres',
  :password => 'postgres123',
  :host => 'localhost'
)

cx = ActiveRecord::Base.connection
# you will see the exception from the connection adapter, but won't see the SQL it tried to run
res = cx.select_all("select * from nonsense_table")

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages