Joelio
Joelio

Reputation: 4691

how to change the rails logger to use standard out from rake tasks (rails2)

When I do

Rails.logger.debug "hello world" from within my rake tasks I want it to log to standard out.

How do I set the rails logger to Logger.new(STDOUT) from within my rake task?

I want my app to log to the file when coming through controllers etc, just want the rake tasks to go to std out because of the way my monitoring is setup.

I was thinking I could define another environment and use that config, but probably overkill, I want all the same environment vars in each env, just want to change the location of my log destination.

For now I have a log helper that uses puts, but I want to take advantage of the formatting of rails logs and the buffering.

Upvotes: 15

Views: 10167

Answers (3)

MartianE
MartianE

Reputation: 404

With rails 4 you will be using the gem rails_12factor. Place this into your Gemfile and voilà! gem 'rails_12factor_'

Upvotes: -1

singpolyma
singpolyma

Reputation: 11241

I just did Rails.logger = Logger.new(STDOUT) and that also worked (rails3)

Upvotes: 11

Pan Thomakos
Pan Thomakos

Reputation: 34350

You can reset the default logger this way:

RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)

You can also set the logger for specific parts of your application (ActiveRecord, ActionController...) like this:

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

Upvotes: 8

Related Questions