60

Can I flush the logs of only one app in Pm2?

Assuming my app id is 2

I tried

pm2 flush 2

but still it flushes all apps' logs.

Pradeep
  • 9,667
  • 13
  • 27
  • 34
Ali Elkhateeb
  • 3,413
  • 4
  • 21
  • 39

4 Answers4

48

It was a bug in pm2.

I submitted an issue and they fixed it.

To solve it on your side, run these commands:

$ npm install pm2@latest -g
$ pm2 update

And it should work with the latest release.

Ali Elkhateeb
  • 3,413
  • 4
  • 21
  • 39
  • 4
    Wow! Not all heroes wear cape. Good job mate. – Hisham Mubarak May 26 '20 at 20:17
  • 4
    well ... pm2 flush works - but it flushes ALL logs for ALL running processes. If you do pm2 flush [n] to only clear the logs for a particular id number then it says "[PM2] Logs flushed" but the logs are untouched ! Moreover, pm2 flush [n] isn't shown as an option on the PM2 cheatsheet – Andy Lorenz Oct 08 '20 at 08:57
  • I'm on PM2 4.5 and it's still buggy! https://github.com/Unitech/pm2/issues/4074#issuecomment-694216056 – Mir-Ismaili May 27 '21 at 20:23
  • I'm on 5.1.2 and it doesn't work! I'm manually truncating the log files. :D – ankush981 Dec 25 '21 at 07:10
  • For those who came across this problem, please take a look on https://stackoverflow.com/a/75166500/12783754. Good luck! – Just some sailboat Jan 19 '23 at 00:26
27

pm2 logs are located in .pm2/logs/

PM2 LOGS COMMANDS :

Show logs

pm2 logs appName|appId --lines=100

Show Error logs

pm2 logs appName|appId --err --lines=100

Empty log for specific app

pm2 flush appName|appId        

Empty all log files

pm2 flush              

Reload all logs

pm2 reloadLogs         
Saurabh Mistry
  • 12,833
  • 5
  • 50
  • 71
18

You can flush log of specific app by mentioning name or id.

pm2 flush my_app_name // by name
pm2 flush my_app_id   // by id
Haris Khurshid
  • 294
  • 2
  • 7
2

Try any one of the following commands to clear the logs in pm2,

pm2 flush        
pm2 flush appName|appId
Codemaker2015
  • 12,190
  • 6
  • 97
  • 81