无法在 PM2 中合并标准和错误日志
Can't merge the standard and error log in PM2
我正在尝试将所有日志保存在一个文件中,因此我正在使用
启动我的应用程序
pm2 start app --merge-logs -l --log "~/webapps/infranodus/infranodus/infralogpm2.log"
应用启动,但文件中没有任何内容,只创建了标准日志。
我试图 touch
创建文件,但这也无济于事。
我使用 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
和下面描述的其他组合。
单个实例不需要 --merge-logs
。根据 pm2 --help
,它表示 "merge logs from different instances but keep error and out separated"。尽管在我的例子中,STDOUT 和 STDERR 都出现在所需的日志文件中,有和没有 --merge-logs
选项。
-l
和 --log
都不应使用。理想情况下,您应该按照 Unix 命令行参数约定只使用其中一个。但是,就我而言,它按照您建议的方式工作,并且仅适用于 --log
.
作为计数器检查的一部分,运行pm2 start ./bin/app2 --output /var/tmp/sample-app2-stdout.log --error /var/tmp/sample-app2-error.log
。它生成两个文件,输出分别来自 console.log
和 console.error
。
对于您的情况,我建议您检查存储日志文件的分区上是否有足够的磁盘 space 可用,然后执行 pm2 delete app
然后重试。
如果这不能解决问题,是否可以共享示例代码和重现问题的确切步骤?
我正在尝试将所有日志保存在一个文件中,因此我正在使用
启动我的应用程序pm2 start app --merge-logs -l --log "~/webapps/infranodus/infranodus/infralogpm2.log"
应用启动,但文件中没有任何内容,只创建了标准日志。
我试图 touch
创建文件,但这也无济于事。
我使用 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
和下面描述的其他组合。
-
单个实例不需要
--merge-logs
。根据pm2 --help
,它表示 "merge logs from different instances but keep error and out separated"。尽管在我的例子中,STDOUT 和 STDERR 都出现在所需的日志文件中,有和没有--merge-logs
选项。-l
和--log
都不应使用。理想情况下,您应该按照 Unix 命令行参数约定只使用其中一个。但是,就我而言,它按照您建议的方式工作,并且仅适用于--log
.作为计数器检查的一部分,运行
pm2 start ./bin/app2 --output /var/tmp/sample-app2-stdout.log --error /var/tmp/sample-app2-error.log
。它生成两个文件,输出分别来自console.log
和console.error
。
对于您的情况,我建议您检查存储日志文件的分区上是否有足够的磁盘 space 可用,然后执行 pm2 delete app
然后重试。
如果这不能解决问题,是否可以共享示例代码和重现问题的确切步骤?