在Ruby中使用守护进程在其他目录中添加日志 [英] Add logs in different directory using daemon in ruby
本文介绍了在Ruby中使用守护进程在其他目录中添加日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用守护程序包装脚本,并在其中指定了日志位置:
脚本如下所示:
I am using daemon to wrap my script and has specified logs location into that : Script looks like this :
#!/usr/local/bin/ruby
require 'rubygems'
require 'daemons'
Daemons.run_proc(
'script_test', # name of daemon
:log_output => true,
:output_logfilename => "script-test.log",
:logfilename => "script-test.log"
) do
exec 'ruby /opt/script-test/script-test.rb'
end
问题是我的日志存储在我的脚本所在的目录中。我必须将日志添加到其他目录(例如/ var / log / script-test),并且以后必须每周轮换这些日志。
为我提供解决方案,以便我可以将脚本的日志存储在/ var / log目录中。
Problem is my logs are storing in same directory where my script is present. I have to add my logs to different directory such as /var/log/script-test and later have to rotate those logs weekly. Provide me with a solution so that i can store the logs of script in /var/log directory.
推荐答案
它使用以下配置为我工作:
It worked for me with this configuration as :
Daemons.run_proc(
'script-test', # name of daemon
:log_output => true,
:dir_mode => :normal,
:dir => "/var/log",
:output_logfilename => "script-test.log",
:logfilename => "script-test.log"
) do
exec 'ruby /opt/script-test/script-test.rb'
end
这篇关于在Ruby中使用守护进程在其他目录中添加日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文