简体   繁体   English

Node.js 记录到文件删除旧日志重新启动

[英]Node.js Logging to File deleting old log on restart

I have a Node.js Application that I execute with systemctl start app.service on my server.我有一个 Node.js 应用程序,我在我的服务器上使用systemctl start app.service执行。 I configured my package.json correctly that on app start the log is being written in app.log with node app.js > app.log 2>&1 the problem is now that with every restart the old log is being deleted and a new one is genereted.我正确配置了我的 package.json,在应用程序启动时,日志正在 app.log 中写入node app.js > app.log 2>&1现在的问题是,每次重新启动都会删除旧日志并生成新日志. I want to keep my old log data for debugging purposes.我想保留我的旧日志数据以用于调试目的。 How can I edit the log statement that the old log will be saved or the new log just appended?如何编辑将旧日志保存或仅附加新日志的日志语句? Is this possible?这可能吗?

I already searched in Stackoverflow and Google for a solution but did not find one.我已经在 Stackoverflow 和 Google 中搜索了解决方案,但没有找到。 I was expecting to keep my old logs.我期待保留我的旧日志。

When using IO redirection, if you want to append to a file rather than overwrite the file, you need to use ">>" instead of ">".当使用IO重定向时,如果你想append到一个文件而不是覆盖文件,你需要使用“>>”而不是“>”。 For example:例如:

node app.js >> app.log

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM