简体   繁体   English

在生产环境中运行时如何在 Rails 控制台中查看详细的错误日志?

[英]How to see verbose error logs in the Rails console when running in production?

One of the biggest challenges I have with my Ruby on Rails application is that troubleshooting production bugs can become extremely painful due to the lack of information in the logs.我在使用 Ruby on Rails 应用程序时遇到的最大挑战之一是,由于日志中缺少信息,对生产错误进行故障排除可能会变得非常痛苦。

I, [2021-01-08T14:42:44.834966 #223]  INFO -- : [1b0730a0-21e4-476f-92a6-6b4d86e98010] undefined method `id' for nil:NilClass
I, [2021-01-08T14:42:44.865441 #223]  INFO -- : [1b0730a0-21e4-476f-92a6-6b4d86e98010] No template found for SubscriptionPaymentController#payment_webhook, rendering head :no_content
I, [2021-01-08T14:42:44.865759 #223]  INFO -- : [1b0730a0-21e4-476f-92a6-6b4d86e98010] Completed 204 No Content in 887ms (ActiveRecord: 7.3ms)

For example, the above code shows an error in production, but there's no verbose information on how to fix it.例如,上面的代码显示了生产中的错误,但没有详细说明如何修复它。 In dev, I believe it would show the specific line number of the code where the error occurred.在开发中,我相信它会显示发生错误的代码的特定行号。

Since this production.log file can't be shown to the user in the UI anywhere, is there any way I could just simply turn on "more" verbose logging so that I can easier figure out where bugs occur in production?由于此production.log文件无法在任何地方的 UI 中显示给用户,有什么方法可以简单地打开“更多”详细日志记录,以便我可以更轻松地找出生产中出现错误的位置?

In your production.rb file you can change config.log_level property to debug , like this config.log_level =:debug .在您的production.rb文件中,您可以将config.log_level属性更改为debug ,例如config.log_level =:debug This is the lowest level available.这是可用的最低级别。 ( more info on log levels ) 有关日志级别的更多信息

HOWEVER this is only recommended to be done in production when you are trying to fix something, but then it should be reverted to a higher level otherwise you risk filling the disk space very fast.但是,仅建议在您尝试修复某些内容时在生产中执行此操作,但随后应将其恢复到更高级别,否则您可能会非常快地填充磁盘空间。

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

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