Redirect the “puts” command output to a log file

后端 未结 4 1196
小蘑菇
小蘑菇 2021-01-31 10:49

I am working on creating a daemon in Ruby using the daemons gem. I want to add output from the daemon into a log file. I am wondering what is the easiest way to redirect p

4条回答
  •  爱一瞬间的悲伤
    2021-01-31 11:29

    If you need to capture both STDERR and STDOUT and don't want to resort to logging, following is a simple solution adapted from this post:

    $stdout.reopen("my.log", "w")
    $stdout.sync = true
    $stderr.reopen($stdout)
    

提交回复
热议问题