无法合并PM2中的标准和错误日志

问题描述 投票:1回答:1

我正在尝试保存所有日志的一个文件,所以我正在使用我的应用程序

pm2 start app --merge-logs -l --log "~/webapps/infranodus/infranodus/infralogpm2.log"

应用程序启动但文件中没有任何内容,只创建了标准日志。

我试图touch创建文件,但这也无济于事。

logging pm2
1个回答
1
投票

我尝试使用NodeJS 10.15和PM2 3.2.4以及以下HelloWorld ExpressJS代码对RHEL 7.4进行了一些检查。

var http = require("http");

http.createServer(function (request, response) {
    // Send the HTTP header 
    // HTTP Status: 200 : OK
    // Content Type: text/plain
    response.writeHead(200, {'Content-Type': 'text/plain'});

    // Send the response body as "Hello World"
    response.end('Hello World\n');
}).listen(8081);

// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');
console.error('This is on STDERR');

假设上面的代码在./bin/app2文件中,并且所需的模块存在于node_modules下,

我运行应用程序作为pm2 start ./bin/app2 --merge-logs -l --log /var/tmp/sample-app2.log和下面描述的其他组合。

  1. 单个实例不需要--merge-logs。根据pm2 --help,它说“合并来自不同实例的日志,但保持错误并分开”。虽然在我的情况下,STDOUT和STDERR都出现在所需的日志文件中,有和没有--merge-logs选项。
  2. 不应该使用-l--log。理想情况下,根据Unix命令行参数约定,您应该只使用其中一个。但是,在我的情况下,它的工作方式与你建议的方式一样,只有--log
  3. 作为反击检查的一部分,运行pm2 start ./bin/app2 --output /var/tmp/sample-app2-stdout.log --error /var/tmp/sample-app2-error.log。它生成两个文件,分别来自console.logconsole.error

在您的情况下,我建议您检查存储日志文件的分区上是否有足够的磁盘空间,并执行pm2 delete app然后再试一次。

如果这不能解决问题,是否可以共享示例代码和重现问题的确切步骤?

© www.soinside.com 2019 - 2024. All rights reserved.