如何更改Rails记录器以使用rake任务中的标准输出(rails2) [英] how to change the rails logger to use standard out from rake tasks (rails2)

查看:87
本文介绍了如何更改Rails记录器以使用rake任务中的标准输出(rails2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样做

在我的rake任务中,Rails.logger.debug"hello world"我希望它登录到标准输出.

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

如何在我的rake任务中将rails logger设置为Logger.new(STDOUT)?

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

我希望我的应用程序在通过控制器等时登录到文件,只是由于我的监控设置方式而使rake任务进入标准输出.

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.

我当时想我可以定义另一个环境并使用该配置,但可能有点过头了,我希望每个env中都具有相同的环境var,只想更改我的日志目标位置.

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.

目前,我有一个使用puts的日志助手,但是我想利用rails日志的格式和缓冲.

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.

推荐答案

我只是做了Rails.logger = Logger.new(STDOUT),它也起作用(rails3)

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

这篇关于如何更改Rails记录器以使用rake任务中的标准输出(rails2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆