在 Rails 中直接“放置”到 Apache 日志
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/751542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Direct "puts" in Rails, to Apache log
提问by Paul
What's the configuration setting to get calls to putsto be written to the Apache log file? (Using Passenger to run Rails on Apache)
将调用puts写入 Apache 日志文件的配置设置是什么?(使用Passenger 在Apache 上运行Rails)
Thanks
谢谢
回答by Ben Crouse
Why not just log to the Rails logs? You can use Rails.loggerto write to the files in your app's log directory.
为什么不直接登录到 Rails 日志?您可以使用Rails.logger写入应用程序日志目录中的文件。
Example:
例子:
Rails.logger.warn "Login failed for user #{@user.login}"
Rails has different logging levels built in (debug, info, warn, error, and fatal), and these can be specified in your environment file. So to set logging in production mode to debug level:
Rails 内置了不同的日志级别(调试、信息、警告、错误和致命),这些可以在您的环境文件中指定。因此,要将生产模式下的日志记录设置为调试级别:
config.log_level = :debug
回答by Oinak
I think you can "reopen" STDOUT to point to whatever RAILS_DEFAULT_LOGGER points to (your passenger log in this case).
我认为您可以“重新打开” STDOUT 以指向 RAILS_DEFAULT_LOGGER 指向的任何内容(在这种情况下是您的乘客日志)。
But I'm not sure it is a Good idea, here is why:
但我不确定这是个好主意,原因如下:
Log is for things you want to know during normal function of your app, and is filtered differently according to your envioronment logger.debug() calls print to development.log but not to production.log, logger.error() goes, logically enough ,everywhere.
日志用于记录您在应用程序正常运行期间想知道的内容,并根据您的环境进行不同的过滤。 ,到处。
STDOUT (p, puts, printf, pretty_print...) is perfect por script/console experiments and for debugger calls, see this: post about ruby-debugfor some hints on how to use "puts" or "p" to watch the values of your variable in the middle of an execution.
STDOUT (p、puts、printf、pretty_print...) 是完美的脚本/控制台实验和调试器调用,请参阅:发布关于 ruby-debug的一些提示,了解如何使用“puts”或“p”来观看执行过程中变量的值。
I hope this can help you.
我希望这可以帮助你。

