Log issue in Rails4 with Docker running rake task

痴心易碎 提交于 2019-12-13 01:13:17

问题


My rails4 application is running with docker. It runs a rake task for fetching messages from AWS SQS.

The problem I met is that logs can't show up in a console in time. The console doesn't show anything until exception/error comes. In other words, if my application works fine, no logs come to console. But if application went wrong, all the logs(info, warn and error) come together!

I already configure the config/production.rb as blow:

config.logger = Logger.new(STDOUT)
config.logger.level = Logger.const_get('INFO')
config.log_level = :info

I google 'rake task log was not working', but nothing useful. Is this a rails log problem or a rake task log problem, or maybe a docker problem?

Hoping that get some advice!


回答1:


Try disabling output buffering to STDOUT. You can do this by adding this line to your rake task:

$stdout.sync = true



回答2:


For Rails 4.x the log level is configuration

# Enable stdout logger
config.logger = Logger.new(STDOUT)

# Set log level
config.log_level = :ERROR

The logger level is set on the logger instance from config.log_level at: (https://github.com/rails/rails/blob/v4.2.4/railties/lib/rails/application/bootstrap.rb#L70)



来源:https://stackoverflow.com/questions/36417888/log-issue-in-rails4-with-docker-running-rake-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!