Search code examples
node.jsstderrforever

Why aren't forever's error messages being logged


I am currently running forever in a bash script:

forever -v  -l log/system.log -e log/systemerr.log -w --watchIgnore '{log,data,node_modules}' app.js

I am also using log4js to capture logging for my app (with the following configuration):

log4js.configure({
  appenders: [
    //{ type: 'console' },
    {
      type: "file", 
      absolute: true, 
      filename: "./log/app.log", 
      maxLogSize: 1000000,
      backups: 10
    }
  ]}); 

Everything seems to be working in the sense that my app's output is being put out to app.log and forever's -l output is going to system.log:

warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms

But the following goes to console and I would have thought it would go to systemerr.log:

error: Could not read .foreverignore file.
error: ENOENT, open '/home/blah/blah/.foreverignore'
error: Forever detected script exited with code: 1
error: Script restart attempt #1

How can I get this error information, which I think is generated by forever, into systemerr.log?


Solution

  • forever -e ERRFILE option desired to:

    Logs stderr from child script to ERRFILE

    Errors produced by forever itself wouldn't be logged here, and this is great as you only get errors produced by your application here.

    If you really want to get the forever errors in file use IO redirection for STDERR in your wrapping bash script like this:

    forever ... 2>> forever-errors.log
    

    If you still want for some reason to get those errors in the same file as your application error log you may redirect and append STDERR to same file as the error log.