Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log issue in Rails4 with Docker running rake task

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!

like image 567
Eason Caizhen Liu Avatar asked Apr 05 '16 05:04

Eason Caizhen Liu


1 Answers

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

$stdout.sync = true
like image 123
alexpls Avatar answered Oct 05 '22 05:10

alexpls