如何剪切日志文件?

时间:2015-04-07 03:54:45

标签: node.js pm2

我使用pm2创建日志文件,它非常大(大约1.2GB,并且仍在增加)。

如何将大日志文件剪切为多个小日志文件?

是否支持pm2自动剪切日志文件?

2 个答案:

答案 0 :(得分:2)

一般情况下,如果pm2允许旋转日志文件,您不必担心,因为您可以使用logrotate实用程序在基于Linux的系统上执行此操作。

更多细节可在以下网址找到:

https://www.digitalocean.com/community/tutorials/how-to-manage-log-files-with-logrotate-on-ubuntu-12-10

http://www.z-car.com/blog/programming/how-to-rotate-logs-using-pm2-process-manager-for-node-js

https://github.com/Unitech/pm2/issues/114

答案 1 :(得分:0)

举个例子: var file = fs.readFileSync('logfile.log') if (file.length > 1024) { // 1KB fs.writeFileSync('logfile.log', file.slice(-1024)) }