How do I use pm2
to log only based off a keyword?
This is how pm2 is being called currently:
package.json file
"services": "pm2 start pm2.config.js --no-daemon",
Application Logs Once an application is started with PM2 you can consult and manage logs easily. Log files are located in the folder $HOME/. pm2/logs .
By default, all logs are saved into $HOME/. pm2/logs .
You can pass /dev/null to error_file or out_file to disable logs saving.
PM2 Runtime is a Production Process Manager for Node. js applications with a built-in Load Balancer. It allows you to keep applications alive forever, to reload them without downtime and facilitate common Devops tasks. Starting an application in production mode is as easy as: $ pm2 start app.js.
I don't know if by default pm2 saves logs in a file, but, when using pm2 log rotate it does. So it works for me:
grep -r "KEYWORD" ~/.pm2/logs
I'm using EC2 Ubuntu and that is the default pm2 logs folder, you may change it according to your setup.
Update: It will not filter the log in real time, but it's useful if you need to find anything on older logs. If you need to filter logs in real time, you can grep the outpu with Hesam B answer, I just tested it, and it works, as shown below.
$ pm2 logs app-name or pid | grep -i Keyword
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With