Ruby 守护进程日志轮换
当我为 Daemons (1.1.0) gem 设置日志记录参数时,如何实现与此行类似的行为?
logger = Logger.new('foo.log', 10, 1024000)
守护进程选项:
options = {
:ARGV => ['start'],
:dir_mode => :normal,
:dir => log_dir,
:multiple => false,
:ontop => false
:mode => :exec,
:backtrace => true,
:log_output => true
}
When I'm setting logging parameters to the Daemons (1.1.0) gem, how would I achieve similar behavior to this line?
logger = Logger.new('foo.log', 10, 1024000)
Daemon options:
options = {
:ARGV => ['start'],
:dir_mode => :normal,
:dir => log_dir,
:multiple => false,
:ontop => false
:mode => :exec,
:backtrace => true,
:log_output => true
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是 Daemons gem 不使用 Logger。它将
STDOUT
和STDERR
直接重定向到文件。您可以在此处查看重定向工作原理的详细信息:
https://github.com/ghazel/daemons /blob/master/lib/daemons/daemonize.rb#L241-261
因此,您必须使用类似 logrotate 并重新启动守护进程。
如果这是不可接受的,我建议像您在问题中提供的那样直接使用
Logger
。Unfortunately the Daemons gem does not use Logger. It redirects
STDOUT
andSTDERR
directly to a file.You can see the details of how the redirection works here:
https://github.com/ghazel/daemons/blob/master/lib/daemons/daemonize.rb#L241-261
Because of this, you will have to use something like logrotate and restart the daemon if you want to do log file rotation.
If this is not acceptable, I would suggest using
Logger
directly like you provided in the question.