11

I am continually running a few server scripts (on different ports) with nodejs using forever.

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. 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.

I have a few questions actually:

  1. Is it ok to keep forever running like this?
  2. If not, is there a proper way to disable logging? The github repository seems to indicate that forever will still log to a default file, which I don't want. Otherwise I may just write a cronjob that periodically stops scripts, truncates logs, then restarts the scripts.
  3. What happens if I just create the logfile again with something like touch logfile_name.log while the script is still running - will this make forever freak out or is this a plausible solution?

Thanks for your time.

3
  • 2
    +1 for very nice question. Commented Jun 10, 2013 at 21:29
  • 1
    Have you considered implementing something like what most logging systems do? Instead of calling console.log directly, write a wrapper function(s) (or use a library) which allows you to assign not only a message, but a logging level, and then based on your configuration, only output logs which are of a certain significance or greater. I would say that's the "proper" way to disable logging. Commented Jun 11, 2013 at 1:33
  • @Bret I no longer work at that company, but that's what I ended up doing - creating various levels of logging. It kept the files small enough that the script rarely had to be stopped to clear the logs before restarting. Commented Aug 16, 2017 at 19:55

3 Answers 3

4

according to https://github.com/foreverjs/forever, try to pass -s to silent all log.

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.

Sign up to request clarification or add additional context in comments.

Comments

2

1) Just build in a periodic function or admin option to clear the forever logs. From the manual forever cleanlogs

2) At least for linux. Send each log file to /dev/null. Each log type is specified by options -l -o and -r. The -a option for append log, will stop it complaining about the log already existing.

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.

1 Comment

I also use log4js but forever continues its own output.
1

There's a nifty tool that can help you that called logrotate. Have a look here

Especially the copytruncate option, it is very useful in your case.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.