Voldum
Voldum

Reputation: 59

PM2 Flush not clearing logs

I run a Ubuntu server which is suddenly full because of pm2 logs taking 16GB. I tried pm2 flush. But this only clears the folder which took 4GB.

enter image description here

As root the ".pm2" folder is cleared but not logs folder. As my own user the folder is cleared but under the wrong username.

Here is showed running pm2 flush in root and admin user.

enter image description here

How do i clear it?

Upvotes: 5

Views: 4711

Answers (2)

Just some sailboat
Just some sailboat

Reputation: 330

Hope I'm not too late. Alright, long story short.

The problem was within the code, the arguments passed aren't implemented correctly to deal with whatever logical comparison or verification they wanted. So as a result, the logs aren't being flushed.

I created an PR, which you can access here. I think it will take some time for the maintainers to review the pull. It may not even get merged at all.


Anyways, if you want to apply and test the updated code to your system. You need to find where your PM2 package files are located.

To do this, just run the commands according to the package manager that you used to install pm2.

Note: If you installed pm2 using sudo, you must ran the commands with sudo too.

yarn => yarn global dir

npm => npm root -g

After that, cd into the directory path that the command returned.

Then cd into <..PATH..>/node_modules/pm2/lib/API. You should see a file named LogManagement.js. Use sudo cp to make a copy of that file. So if there's any problem, you can still turn back.

Following, go to this github link, and replace the entire LogManagement.js with the copied code.

Done! You should be able to run pm2 flush "My App" or something like pm2 flush 1 as usual.

Upvotes: 2

Prithvi Sharma
Prithvi Sharma

Reputation: 63

you should try pm2 flush <app_name> it will remove the default output and error logs from .pm2/logs the above command does not flush the merge logs for the specified app_name

Upvotes: 2

Related Questions