开发者

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 co开发者_C百科uld 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.


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


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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜