NodeJS/Forever archive logs

被刻印的时光 ゝ 提交于 2019-12-03 04:22:42

问题


I am using forever to run my node application. When I start forever I specify where to write the logs. I also specify to append to the log. Problem here is that my log is going to grow out of control over the course of months.

Is there any way to archive/roll logs on an interval, i.e. every day roll/archive what is in the log file to another file (i.e. server-2013-3-5.log). That way I can delete/move off old log files as needed.

I have just started looking into using Winston for my logger and I have not come across anything there that would help.

Any ideas?


回答1:


forever itself doesn't support log rotation and log rotation is still a pending feature request for Winston.

You can use logrotate which is included in most Linux distributions and is used for rotating system log files, as well as used by other software like Apache.

Add a file to /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.
}

See more logrotate examples.



来源:https://stackoverflow.com/questions/15231968/nodejs-forever-archive-logs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!