简体   繁体   English

Rails STDOUT 日志没有出现在 kubectl 日志和 datadog 日志中

[英]Rails STDOUT logs are not coming in kubectl logs and datadog log

We have set logger as STDOUT in the rails configuration.我们在 rails 配置中将 logger 设置为 STDOUT。

  config.log_level = :info
  config.logger = Logger.new(STDOUT)

We are expecting these logs in kubectl logs as well as datadog logs but STDOUT is not showing up there.我们希望这些日志出现在 kubectl 日志和 datadog 日志中,但 STDOUT 没有出现在那里。 We tried below code to test it.我们尝试了下面的代码来测试它。

def method_name
  system('echo testing logging') - this shows up in kubectl/datadog logs
  Rails.logger.info('STDOUT - testing logging') - this does not show up in kubectl/datadog log
end

We have changed the logger setting to output the logs to container file descriptor.我们更改了记录器设置以将日志输出到容器文件描述符。

Reference: https://blog.eq8.eu/til/ruby-logs-and-puts-not-shown-in-docker-container-logs.html参考: https ://blog.eq8.eu/til/ruby-logs-and-puts-not-shown-in-docker-container-logs.html

Try to use the default config and make sure to set the environment variable RAILS_LOG_TO_STDOUT=true , for your deployment/replica set, and in production mode ( RAILS_ENV=production ).尝试使用默认配置并确保为您的部署/副本集设置环境变量RAILS_LOG_TO_STDOUT=true并处于生产模式( RAILS_ENV=production )。 (In dev mode it always logs to console per default). (在开发模式下,它总是默认记录到控制台)。

Actually, the official rails docker images used to have that set, but the newer recommended ruby docker images - of course - do not have Rails specific environment variables set.实际上,官方的 rails docker 镜像曾经设置过该设置,但较新的推荐 ruby​​ docker 镜像 - 当然 - 没有设置 Rails 特定的环境变量。

(more: search for RAILS_LOG_TO_STDOUT in the release notes here , and see PR here ) (更多:在此处的发行说明中搜索RAILS_LOG_TO_STDOUT ,并在此处查看PR

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

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