问题
I see here http://socket.io/docs/logging-and-debugging/ that if I want to run logs, I do like this:
DEBUG=* node yourfile.js
this works.
But I want to also run process with forever.
https://www.npmjs.com/package/forever
But now actually I do not even know if I need forever. Then intention of running forever was - if server dies - forever restarts it.
But the problem is that server dies, clients cannot connect and forever does not restart it. Then node process is using socket.io.
So as I understand - process is not dead, but there is something wrong inside the process - with socket.io.
After we restart node server file, it is working again, for about 2 weeks.
As far as I remember - I need forever to run node process in the background. Otherwise process will be stopped when I close terminal.
How do I run command
DEBUG=* node yourfile.js
with forever so it would log output to files?
I tried like this
$ forever -c 'DEBUG=* node' server.js
but it did not work.
Also tried like this:
forever -o out.log -e err.log my-script.js
But also did not work, it looks different.
Running like this:
forever -o out.log -e err.log start my-script.js
starts proccess, but when I run
forever logs
I do not see any logs, so its no the same.
DEBUG=* node yourfile.js
floods many logs instantly. I am not sure if I want that much logs, but I have no idea how to solve disconnection problem.
Update
Based on comments I tried like this:
DEBUG=* forever start server.js > node.log
node.log file was created, but it just has 3 lines, which means it is not the same log as is when I run
DEBUG=* node server.js
This is what the logs look like which I want to see in text files.
socket.io:server initializing namespace / +0ms
socket.io:server creating engine.io instance with opts {"path":"/socket.io"} + 5ms
socket.io:server attaching client serving req handler +3ms
来源:https://stackoverflow.com/questions/31849480/how-to-run-node-js-process-with-forever-and-logging