[英]How do I use npm forever-monitor to log to stdout
I have a simple nodejs docker service. 我有一个简单的nodejs docker服务。 I'm watching stdout in development and logging to AWS cloudwatch in production.
我正在开发stdout并在生产中登录AWS cloudwatch。
I've just added forever-monitor, but that breaks my logging. 我刚刚添加了永远监视器,但这打破了我的日志记录。 So I've started catching stdout on the child process,
所以我开始在子进程上捕获stdout,
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? 如何将我的
console.log
语句恢复为std-out?
It looks like data
is a stream (see node docs ). 看起来
data
是一个流(参见节点文档 )。
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).
(我发现这个问题很有用)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.