在独角兽中滚动日志
使用 Rails 2.3.5 和 Unicorn 每天滚动日志的最佳方式是什么。如果有多个 Unicorn 实例正在运行,则 Logger 类的常规日志滚动参数不起作用,因为所有工作人员都不会重置其文件句柄。
在 Unicorn 页面上,我看到有人建议 USR1。对此进行一些澄清:
- 这是否会导致日志文件以新名称和新名称滚动 日志文件被打开?
- 每当发生翻转时,我仍然存在将现有日志重命名为下一个版本的问题。
大多数人使用 std Unix logrotate 来实现这一点吗?
Whats the best way to roll logs on a daily basis using Rails 2.3.5 and Unicorn. The general log rolling params to the Logger class don't work if there are multiple instances of Unicorn running as all the workers will not get their file handles reset.
On the Unicorn pages I saw USR1 being suggested. A few clarifications on it:
- Does this cause the log file to be rolled with a new name and a fresh
log file gets opened? - I still have the issues of renaming the existing logs to the next version whenever the rollover happens.
Do most folks use the std Unix logrotate to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能已经这样做了,但首先您应该让每个工作人员记录到不同的文件(以免获得混合日志)。我认为(不完全确定)Rails 2.3 使用旧版本的 BufferedLogger 进行日志记录,它具有一些刷新功能,可以避免这种日志分离。但从 Rails 3.2 开始,刷新是在操作系统级别完成的,因此不能依赖在同一文件上正确打印日志。
在这里寻找解决方案:
在主要问题上,对于较新的 Rails (3.2+) 也禁用了滚动,因此我建议使用 logrotate;你永远不知道什么时候会升级。
logrotate
You might be doing it already but first you should make each worker log to a different file (to not get mixed logs). I think (not completely sure) Rails 2.3 uses an old version of BufferedLogger for logging that has some flushing capabilities that avoid this log separation. But as of Rails 3.2 the flushing is done OS level so cannot rely on the logs being printed properly on the same file.
Look here for solutions on that:
On the main question, rolling has been also disabled for newer Rails (3.2+) so I suggest using logrotate; you never know when you are going to upgrade.
logrotate