[英]Disable logging in a node.js script running with forever
I am continually running a few server scripts (on different ports) with nodejs using forever. 我不断使用nodejs运行一些服务器脚本(在不同的端口上)。
There is a considerable amount of traffic on some of these servers. 其中一些服务器上有大量的流量。 The console.log commands I have for tracking connection anomalies result in bloated log files that I don't need all of the time - only for debugging.
我用于跟踪连接异常的console.log命令导致我不需要一直都需要的膨胀日志文件 - 仅用于调试。 I have been manually stopping the scripts late at night, truncating the files, and restarting them.
我一直在深夜手动停止脚本,截断文件,然后重新启动它们。 This won't do for long term, so we decided to find a solution.
这不会长期,所以我们决定找到一个解决方案。
Someone else on my system deleted the log files I had set up for each of the servers without my knowledge. 我的系统中的其他人在我不知情的情况下删除了我为每个服务器设置的日志文件。 Calling forever list on the command line shows that the server scripts are still running but now I can't tail the log files to see how the nodes are doing.
在命令行上调用永远列表显示服务器脚本仍在运行,但现在我无法查看日志文件以查看节点的运行情况。
Node downtime should be kept to a bare minimum, so I'm hesitant to stop the servers during daylight hours for longer than a few minutes. 节点停机时间应该保持在最低限度,所以我不愿意在白天停止服务器超过几分钟。 Initial testing from the client side seems to indicate that the scripts are doing fine, but I can't be 100% sure there are no errors due to failed attempts at logging to a nonexistent file .
客户端的初始测试似乎表明脚本运行正常,但我不能100%确定没有因为尝试登录到不存在的文件失败而导致错误。
I have a few questions actually: 我实际上有几个问题:
Thanks for your time. 谢谢你的时间。
according to https://github.com/foreverjs/forever , try to pass -s to silent all log. 根据https://github.com/foreverjs/forever ,尝试将-s传递给silent所有日志。
forever -s start YOURSCRIPT
Surely, before doing this, try to update forever to the latest: 当然,在此之前,请尝试永远更新到最新版本:
sudo curl -L https://npmjs.com/install.sh | sudo sh
sudo npm update -g
. sudo npm update -g
。
1) Just build in a periodic function or admin option to clear the forever logs. 1)只需构建一个定期函数或管理选项来清除永久日志。 From the manual
forever cleanlogs
从手册
forever cleanlogs
2) At least for linux. 2)至少对于linux。 Send each log file to
/dev/null
. 将每个日志文件发送到
/dev/null
。 Each log type is specified by options -l
-o
and -r
. 每个日志类型由选项
-l
-o
和-r
指定。 The -a
option for append log
, will stop it complaining about the log already existing. append log
的-a
选项将阻止它抱怨已存在的日志。
forever start -a -l /dev/null -o /dev/null -r /dev/null your-server.js
Perhaps employ your own logging system, I use log4js
, it doesn't complain if I delete the log file while the node process is still running. 也许使用你自己的日志系统,我使用
log4js
,如果在节点进程仍在运行时删除日志文件,它不会抱怨。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.