简体   繁体   English

Rails.logger.debug或puts?

[英]Rails.logger.debug or puts?

我一直在使用此“ puts”检查生产中的某些值,然后可以在日志中看到它,因此“ Rails.logger.debug”或“ puts”是在生产日志中获取该值的最佳方法。

Use Rails.logger . 使用Rails.logger Logger comes with different levels (from 0 to 5) like: 记录器具有不同级别 (从0到5),例如:

  1. Debug 除错
  2. Info 信息
  3. Warn 警告
  4. Error 错误
  5. Fatal 致命
  6. Unknown 未知

Logging will help you to tag the message nicely and in the file, it then appears in proper log format (with timestamps and request_ids if enabled). 日志记录将帮助您更好地标记消息并在文件中进行标记,然后以正确的日志格式显示(带有时间戳和request_ids(如果已启用))。

This is useful when you want to log under development or staging without flooding your production log with unnecessary information. 当您要记录开发中或暂存而不用不必要的信息充斥生产日志时,这很有用。

puts will not give all the above flexibility. puts不会给予上述所有灵活性。 If you are using either from development debugging point of view, it doesn't matter much, but I would still prefer Rails.logger for request_id tagging purposes :) 如果您是从开发调试的角度使用任何一种,都没关系,但是出于请求request_id的目的,我还是更喜欢Rails.logger :)

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

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