简体   繁体   中英

How do I use npm forever-monitor to log to stdout

I have a simple nodejs docker service. I'm watching stdout in development and logging to AWS cloudwatch in production.

I've just added forever-monitor, but that breaks my logging. So I've started catching stdout on the child process,

const forever = require('forever-monitor');

const child = new (forever.Monitor)('server.js', {
  max: 3,
  silent: true,
  args: []
});

child.on('stdout', function(data) {
  console.log(data);
});

but that just gives me byte code out -

[nodemon] starting `node forever.js`
<Buffer 63 6f 6e 6e 65 63 74 65 64 20 74 6f 20 6c 69 76 65 20 64 62 0a>

How do I get my console.log statements back into std-out?

It looks like data is a stream (see node docs ).

I've updated my code to -

child.on('stdout', function(data) {
  console.log(data.toString());
});

And now it's working as expected. (I found this question useful).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM