4

I am using forever (https://github.com/nodejitsu/forever) to run my nodejs application:

forever start app.js

However, it is creating HUGE log files. After 2 days, I have 8GB of logs. The logs are all stored in /home/.forever

Is it possible to turn of the logging feature from the command line, or should I edit my app somehow?

alias51
  • 8,178
  • 22
  • 94
  • 166
  • How much does your app print out? – Corey Ogburn Dec 18 '13 at 18:35
  • It spits a fair bit out via console.log(). Does console.log() in the app write to the logfile (I thought this was just the browser)? – alias51 Dec 18 '13 at 18:39
  • 1
    According to [their blog post](http://blog.nodejitsu.com/keep-a-nodejs-server-up-with-forever) under Additional Forever Options: Unless otherwise specified, the output of the child process' stdout and stderr will be written to [the main log file]. – Corey Ogburn Dec 18 '13 at 18:41

2 Answers2

4

console.log() writes to the standard output of your process (stdout), so you can tell forever to store the output of stdout in /dev/null:

$ forever -o /dev/null index.js
Paul Mougel
  • 16,728
  • 6
  • 57
  • 64
  • Thanks, what does that achieve? Is /dev/null effectively a void area of the disk? – alias51 Dec 18 '13 at 18:42
  • 1
    It's a void device that will never store anything and when being read from will return nothing (although the read will succeed). – Corey Ogburn Dec 18 '13 at 18:43
  • Indeed, `/dev/null` is a virtual file that doesn't really exist but where applications can write to. Everything that is written to `/dev/null` is forgotten. – Paul Mougel Dec 18 '13 at 18:43
  • 1
    If you're running this on Windows, use `NUL` – Corey Ogburn Dec 18 '13 at 18:44
  • 1
    The data won't even touch the disk. I don't actually know the performance impact of using `/dev/null`, but I guess it's negligible: see [this relevant answer](http://stackoverflow.com/a/2725179/2137601). – Paul Mougel Dec 18 '13 at 18:48
4

Paul's answer did not work for me, but gave me some pointers on how to do it:

forever start -o /dev/null -l /dev/null -a script.js

From the documentation:

-l  LOGFILE      Logs the forever output to LOGFILE
-o  OUTFILE      Logs stdout from child script to OUTFILE

Depending on your process, you may also need to redirect STDERR:

-e  ERRFILE      Logs stderr from child script to ERRFILE
Brad
  • 159,648
  • 54
  • 349
  • 530
Hoffmann
  • 14,369
  • 16
  • 76
  • 91