Rod
Rod

Reputation: 15423

Is there a way to only show log based on a keyword in pm2?

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",

Upvotes: 13

Views: 16733

Answers (3)

Kunal Ranjan
Kunal Ranjan

Reputation: 195

$ pm2 logs app-name or pid | grep -i Keyword

Upvotes: 5

Alcides Bezerra
Alcides Bezerra

Reputation: 435

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.

enter image description here

Upvotes: 11

Hesam B.
Hesam B.

Reputation: 65

You can grep the log output if that helps

$ pm2 logs | grep -i "KEYWORD"

Upvotes: 3

Related Questions