简体   繁体   English

将Rails中的“ puts”直接定向到Apache日志

[英]Direct “puts” in Rails, to Apache log

What's the configuration setting to get calls to puts to be written to the Apache log file? 什么是将要调用的puts写入Apache日志文件的配置设置? (Using Passenger to run Rails on Apache) (使用乘客在Apache上运行Rails)

Thanks 谢谢

Why not just log to the Rails logs? 为什么不只是登录到Rails日志? You can use Rails.logger to write to the files in your app's log directory. 您可以使用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. Rails内置了不同的日志记录级别(调试,信息,警告,错误和致命),可以在您的环境文件中指定这些级别。 So to set logging in production mode to debug level: 因此,将生产模式下的日志记录设置为调试级别:

config.log_level = :debug

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. 日志用于在应用程序正常运行期间要了解的事情,并根据环境进行不同的过滤。logger.debug()调用print到development.log,而不是production.log,logger.error()在逻辑上足够,到处。

STDOUT (p, puts, printf, pretty_print...) is perfect por script/console experiments and for debugger calls, see this: post about ruby-debug for 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 ...)是完美的por脚本/控制台实验,对于调试器调用,请参见: 有关ruby-debug的帖子,以获取有关如何使用“ puts”或“ p”观看电视节目的一些提示。执行过程中变量的值。

I hope this can help you. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM