Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Setting ActiveRecord::Base.logger is not effective

#4816

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")

Reported by Doug Daniels · June 10th, 2010 @ 02:15 AM

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: none

Activity

  1. Doug Daniels
    Doug Daniels

    I think it's b/c I needed to use the Railties require instead of the straight require:

    require 'active_record/railtie'
    

    Seems like you can't run it directly w/o Railties.

    June 10th, 2010 @ 03:06 PM

  2. José Valim
    José Valim
    • Milestone cleared.
    • Assigned user set to José Valim

    June 22nd, 2010 @ 05:06 PM

  3. Repository
    Repository
    • State changed from new to resolved

    (from [6788db824ab732b13493a9d702dd8fb89fa153c8]) Move Rails::LogSubscriber to ActiveSupport::LogSubscriber, allowing frameworks like ActiveRecord and ActiveResource to log outsude Rails::Application [#4816 Setting ActiveRecord::Base.logger is not effective state:resolved] http://github.com/rails/rails/commit/6788db824ab732b13493a9d702dd8f...

    June 24th, 2010 @ 12:27 PM

  4. Prem Sichanugrist (sikachu)
    Prem Sichanugrist (sikachu)
    • State changed from resolved to open

    José, after you have moved the Rails::LogSubscriber to ActiveSupport::LogSubscriber, seems like you left out one obsolete test case. I've attached the patch to remove it, and it should make the railtie_test to pass again.

    June 24th, 2010 @ 05:25 PM

  5. Repository
    Repository
    • State changed from open to resolved

    (from [974196b0910924d08640703cc558c48ca049246a]) Remove obsolete test case, since we have move Rails::LogSubscriber to ActiveSupport::LogSubscriber in [6788db824ab732b13493a9d702dd8fb89fa153c8] [#4816 Setting ActiveRecord::Base.logger is not effective state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/974196b0910924d08640703cc558c4...

    June 24th, 2010 @ 07:21 PM

  6. Jeremy Kemper