[英]Logs don't flush in Rails 5
We have an Rails 5 application running on Heroku.我们有一个在 Heroku 上运行的 Rails 5 应用程序。 When we try to run-off process using
heroku run:detached
, the log doesn't appear until the process exits.当我们尝试使用
heroku run:detached
进程时,日志不会出现,直到进程退出。 An example:一个例子:
$ heroku run:detached 'rails runner "Rails.logger.info 1;(1..500000000).each{};"'
Running rails runner "Rails.logger.info 1;(1..500000000).each{};" on ⬢ <REDACTED>... done, run.7268 (Standard-1X)
Run heroku logs --app <REDACTED> --dyno run.7268 to view the output.
$ heroku logs --dyno run.7268 -t
2019-10-24T13:49:29.846280+00:00 heroku[run.7268]: Starting process with command `rails runner "Rails.logger.info 1;(1..500000000).each{};"`
2019-10-24T13:49:30.582293+00:00 heroku[run.7268]: State changed from starting to up
2019-10-24T13:50:01.002636+00:00 heroku[run.7268]: State changed from up to complete
2019-10-24T13:50:00.982354+00:00 heroku[run.7268]: Process exited with status 0
2019-10-24T13:50:00.930084+00:00 app[run.7268]: I, [2019-10-24T13:49:35.871352 #4] INFO -- : 1
The log doesn't appear before the process exits.在进程退出之前不会出现日志。 You can see the Rails timestamp of the last line is
13:49:35
, while the log timestamp is 13:50:00
.您可以看到最后一行的 Rails 时间戳是
13:49:35
,而日志时间戳是13:50:00
。 We see the same behavior in our Rails 6 application, but not in Rails 4 application.我们在 Rails 6 应用程序中看到了相同的行为,但在 Rails 4 应用程序中没有。
We found out this is because of buffering in Rails logger which is enabled in production mode.我们发现这是因为在生产模式下启用的 Rails 记录器中的缓冲。 You can disable it with
STDOUT.sync = true
in production.rb
file.您可以在
production.rb
文件中使用STDOUT.sync = true
禁用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.