如何更改rails logger以从rake任务中使用标准输出(rails2)

时间:2022-05-31 22:27:47

When I do

当我做

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

Rails.logger.debug来自我的rake任务中的“hello world”我想让它登录到标准输出。

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

如何从我的rake任务中将rails记录器设置为Logger.new(STDOUT)?

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.

我希望我的应用程序在通过控制器等时登录到文件,只是因为我的监视设置方式,所以希望rake任务进入std。

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.

现在我有一个使用puts的日志助手,但我想利用rails日志和缓冲的格式。

3 个解决方案

#1


9  

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

我刚做了Rails.logger = Logger.new(STDOUT),这也有用(rails3)

#2


6  

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,ActionController ...),如下所示:

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

#3


0  

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

使用rails 4,您将使用gem rails_12factor。把它放到你的Gemfile中,然后瞧!宝石'rails_12factor_'

#1


9  

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

我刚做了Rails.logger = Logger.new(STDOUT),这也有用(rails3)

#2


6  

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,ActionController ...),如下所示:

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

#3


0  

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

使用rails 4,您将使用gem rails_12factor。把它放到你的Gemfile中,然后瞧!宝石'rails_12factor_'