Node: log files with Forever

“Forever” has arguments to set log file output. It’s important to get the order of the arguments correct (your file goes at the end), because anything after the javascript file name is passed as arguments to your script.

node_modules/forever/bin/forever start \
 -l /var/log/ssl-search-forever.log \
 -o /var/log/ssl-search-output.log \
 -e /var/log/ssl-search-error.log \
 index.js

You can then watch the output of these, like so:

tail -f /var/log/ssl-search-*

You also probably want log rotation – this is what I’m using (will update later if I run into problems with it)

/var/log/ssl-search*.log {
  daily
  dateext
  missingok
  rotate 7
  compress
  delaycompress
  notifempty
  copytruncate
}

If you want to control what goes into the access logs, you need to set up morgan correctly (this needs to happen at the beginning of the node app, not at the end):

app.use(require("morgan")("combined"));

Interested in JavaScript? I send out weekly, personalized emails with articles and conference talks. Click here to see an example and subscribe.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *