keymetrics / pm2-logrotate

Automatically rotate all applications logs managed by PM2
1.24k stars 138 forks source link

Unable to delete files on Windows #170

Open Tpessia opened 3 years ago

Tpessia commented 3 years ago

Hey guys! Seems like the delete_old function is unable to delete retained logs on Windows with these PM2 configs:

{ "apps": [{ "name": "server", "logDateFormat": "YYYY-MM-DD HH:mm:ss Z", "errorFile": "./logs/server-err.log", "outFile": "./logs/server-out.log", "mergeLogs": true, "script": "./index.js" }] }

The problems appears to be related to this line: var fileBaseName = file.substr(0, file.length - 4).split('/').pop() + "__";

On my machine the split fails because the path has "\" and not "/".

Because of that the following line fails to match the path, and no file is queued for deletion: if (files[i].indexOf(fileBaseName) >= 0)