god icon indicating copy to clipboard operation
god copied to clipboard

log does not write until process is stopped

Open twiz718 opened this issue 11 years ago • 9 comments

the log file does not get written to when god process is running in the background until i killed the process.

here is my command for running god: ruby /home/alex/.rvm/gems/ruby-2.1.2/bin/god -c streaming_watcher.god

here is my streaming_watcher.god:

God.watch do |w|
  w.name = "streaming_watcher"
  w.start = "/home/alex/.rvm/rubies/ruby-2.1.2/bin/ruby /home/alex/removed/bin/streaming_watcher.rb"
  w.log = "/home/alex/removed/log/streaming_watcher.log"
  w.env = { 'RAILS_ROOT' => "/home/alex/removed", 'RAILS_ENV' => "production" }
  w.keepalive
end

the file /home/alex/removed/log/streaming_watcher.log has nothing added to it if i watch it via tail -f until i kill the god process. then everything gets written to it...

twiz718 avatar May 26 '14 03:05 twiz718

This isn't something I've seen before.

My best guess is the logger you're using isn't flushing to STDOUT until you exit the process.

eric avatar May 26 '14 03:05 eric

yeah, i get that, but im not doing anything except using puts in the rb script im running.

twiz718 avatar May 26 '14 03:05 twiz718

do i need to manually call $stdout.flush or something?

twiz718 avatar May 26 '14 03:05 twiz718

Could you try adding STDOUT.sync = true to the top of your script?

eric avatar May 26 '14 03:05 eric

yeah, that worked. may want to document this :+1:

twiz718 avatar May 26 '14 03:05 twiz718

just got this in my log file: /usr/bin/env: ruby_executable_hooks: No such file or directory

twiz718 avatar May 26 '14 03:05 twiz718

I would guess that you're running into something rvm-related and I'm not going to be much help there. sorry.

eric avatar May 26 '14 04:05 eric

yah, googled it... http://stackoverflow.com/questions/18936933/bundle-update-env-ruby-executable-hooks-no-such-file-or-directory

twiz718 avatar May 26 '14 04:05 twiz718

I've landed here while looking for solution to the same problem but completely unrelated to this Gem, I'm using basic Ruby's Logger and I had to add the second line on this snippet for it to work:

file         = File.open('/var/log/thisistotallyalogfile.log', File::WRONLY | File::APPEND | File::CREAT)
file.sync = true
logger       = Logger.new(file, 'daily')
logger.level = Logger::INFO 

decided to try after the STDOUT.sync = true comment if the same would apply to the file handler and it did :)

awls99 avatar Aug 02 '18 09:08 awls99