I have a pretty standard and small Rails 6.1.2.1 app on heroku. When tailing the logs (heroku log -a my-app -t) and making an http request to the app, the application logs (via puts or Rails.logger.info don't show up until I restart the dyno. That is, if I run heroku restart or scale the dyno down + back up, all the recent requests I made show up.
Interestingly, if I make a few dozen requests to my app, the logs will eventually start appearing in batches. Likewise, if I force rails to log a ton of stuff (eg by putting 1000.times { Rails.logger.info("foo") } in a controller), that will show up in the heroku logs immediately.
So it kinda seems like either Rails or heroku is buffering the logs somewhere. This doesn't happen on a brand-new heroku/rails app, so I'm not sure what's happening. The fact that I can't effectively tail the production logs makes it really hard to debug live issues.
I've tried setting up an external log drain (Papertrail) instead of relying on heroku log -t, but it exhibits the same behavior. I haven't touched the default logging config in production.rb:
if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end How can I fix/disable this buffering/batching behavior?
https://stackoverflow.com/questions/66523155/heroku-rails-logs-not-showing-until-restart March 08, 2021 at 09:05AM
没有评论:
发表评论