lib/writefully/cli.rb in writefully-0.4.7 vs lib/writefully/cli.rb in writefully-0.4.8

- old
+ new

@@ -11,10 +11,11 @@ def start(file) config = Writefully.config_from(file) if options.daemonize? ::Process.daemon(true, true) + setup_logger(config[:logfile]) write(::Process.pid, config[:pidfile]) spawn(listen(config)) else ::Signal.trap("INT") { $stdout.puts "Writefully exiting..."; exit } listen(config) @@ -43,9 +44,19 @@ end no_tasks do def listen(config) Writefully::Process.new(config).listen + end + + def setup_logger(logfile) + [$stdout, $stderr].each do |io| + File.open(logfile, 'ab') do |f| + io.reopen(f) + end + io.sync = true + end + $stdin.reopen('/dev/null') end def write pid, pidfile File.open pidfile, "w" do |f| f.write pid