Question

Problem:

I am using the popular Foreman gem to run a number of rails scripts/daemons. I'm encountering a problem with getting the output of one of my scripts to display in the foreman console.

I'm using a ruby Logger instance to handle all of the logging in the script and I'm initializing the logger to output to STDOUT like so:

logger = Logger.new(STDOUT)

None of the output is appearing in Foreman. Why is this?

Other tidbits:

I have the following require at the top of my script. puts [message] outputs to the foreman console when run before this require, but no output occurs if run after. The p command works in either instance.

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))

If I initialize the logger to STDERR instead, it works.

Was it helpful?

Solution

Found the answer in the foreman wiki on github:

If you are not seeing any output from your program, there is a likely chance that it is buffering stdout. Many languages such as Ruby and Python buffer stdout by default. To disable this behavior, add this code as early as possible in your program:

$stdout.sync = true

source: https://github.com/ddollar/foreman/wiki/Missing-Output

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top