如何让 Rails 记录我的 Rack::CommonLogger 消息?
我正在使用 ruby gem rest-client 和 rest-client com/crohr/rest-client-components" rel="nofollow">rest-client-components。
Rest-client-components 支持使用 Rack::CommonLogger 进行请求日志记录。
启用它的说明使用 STDOUT:
require 'restclient/components'
RestClient.enable Rack::CommonLogger, STDOUT
这在开发中工作得很好,但是当我使用 Apache/Passenger (mod_rails) 进行生产时,我在 production.log 中看不到来自rest-client 的任何消息。有没有办法将 Rack::CommonLogger 与 Rails 日志集成?或者至少将其写入文件?前者更有用,因为很容易看到上下文,但后者总比没有好。
谢谢。
I am using the ruby gem rest-client with rest-client-components.
Rest-client-components enables request logging with Rack::CommonLogger.
The instructions for enabling it make use of STDOUT:
require 'restclient/components'
RestClient.enable Rack::CommonLogger, STDOUT
This works fine in development, but when I'm in production with Apache/Passenger (mod_rails), I don't see any messages from rest-client in production.log. Is there a way to integrate Rack::CommonLogger with the Rails log? Or at least to write it to a file? The former is more useful because it's easy to see the context, but the latter is better than nothing.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我想出的解决方案。
感谢@crohr 为我指明了正确的方向。
首先,创建一个新的 Logger 类。 Rails 默认为 ActiveSupport::BufferedLogger,因此我们将对其进行扩展。
然后告诉 Rails 使用你的新记录器。
最后,告诉rest-client使用您的新记录器。
限制:
如果您将 Rack::Cache 与 rest-client-components 一起使用,则不会捕获缓存消息。
Here's the solution I came up with.
Thanks to @crohr for pointing me in the right direction.
First, create a new Logger class. Rails defaults to ActiveSupport::BufferedLogger, so we'll extend that.
Then tell Rails to use your new logger.
Finally, tell rest-client to use your new logger.
Limitations:
If you're using Rack::Cache with rest-client-components, this doesn't capture the cache messages.