NodeJS / Forever归档日志

我永远用来运行我的节点应用程序。 当我永远开始时,我指定在哪里写日志。 我也指定追加到日志。 这里的问题是我的日志会在几个月的时间内失控。

有什么办法可以在一个时间间隔内存档/滚动日志,也就是每天滚动/归档日志文件中的内容到另一个文件(即server-2013-3-5.log)。 这样我可以根据需要删除/移出旧的日志文件。

我刚开始考虑使用温斯顿为我的logging器,我没有遇到任何有用的东西。

有任何想法吗?

永远本身不支持日志旋转和日志旋转仍然是Winston的一个待决function请求 。

您可以使用大多数Linux发行版中包含的logrotate ,用于轮换系统日志文件,以及其他软件(如Apache)使用。

添加一个文件到/etc/logrotate.d/

 /path/to/server.log { daily # how often to rotate rotate 10 # max num of log files to keep missingok # don't panic if the log file doesn't exist notifempty # ignore empty files compress # compress rotated log file with gzip sharedscripts # postrotate script (if any) will be run only once at the end, not once for each rotated log copytruncate # needed for forever to work properly dateext # adds date to filename dateformat %Y-%m-%d. } 

查看更多的logrotate示例 。