pm2下的自定义日志记录 [英] custom logging under pm2

查看:591
本文介绍了pm2下的自定义日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写给console.log

node server.js >> /var/log/nodeserver.log 2>&1

但是,在 pm2 下尝试相同的操作时:

However, when trying the same under pm2:

pm2 start server.js >> /var/log/pm2server.log 2>&1

日志文件仅显示 pm2 启动信息

the log file only shows the pm2 startup information

使用 pm2 是否完全可以记录应用程序?他们在他们的页面上讨论日志记录,并显示带有"log message from echo.js"之类的文本的图像,但我对将自定义信息添加到 pm2 日志中一无所获.

Is application logging at all possible with pm2? On their page they discuss logging, and show an image with text like "log message from echo.js", but I see nothing about getting custom information into the pm2 log.

推荐答案

与pm2一起运行时,您的应用程序日志将驻留在$HOME/.pm2/logs中,如

When running with pm2 your application logs will reside in $HOME/.pm2/logs as described here. Verifying this locally with a simple index.js file that outputs console.log('test')

$ pm2 start index.js
[PM2] Spawning PM2 daemon
[PM2] PM2 Successfully daemonized
[PM2] Starting index.js in fork_mode (1 instance)
[PM2] Done.
┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬────────────┬──────────┐
│ App name │ id │ mode │ pid   │ status │ restart │ uptime │ memory     │ watching │
├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼────────────┼──────────┤
│ index    │ 0  │ fork │ 36976 │ online │ 0       │ 0s     │ 9.258 MB   │ disabled │
└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴────────────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app

请注意,在这里我看不到console.log输出,但是,如果我导航到$HOME/.pm2/logs会看到

Notice how I see no console.log output here, but, if I navigate to $HOME/.pm2/logs I see

logs $ ls
index-error-0.log   index-out-0.log

logs $ cat index-out-0.log
test

这篇关于pm2下的自定义日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆