Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's this PR about?
This PR aims to fix and restore the ability to use either
pm2 flush <app_id>
orpm2 flush <app_name>
to flush logs successfully.Why so many commits?
In the first commit of this PR, I used a regex to extract a valid filename from a log path to allow the existing
if-else
comparison to continue working whatever it's intended.It worked perfectly. Well only if the user didn't seek to customize their logging path or name! Because it's found out later that this solution isn't feasible as it would mean that a log file must end with an extension of
.log
, or else the flush will not work.An example is when a user tries to redirect stderr to a file like
~/myApp/logs/process.error
, the solution will not be able to handle this. Hence, I have chosen to revert the changes made by the first commit.About the latest commit
Now, about the latest commit of this PR. The printout msg of flushing a log file has been moved inside their respective
if
block. This fixed a problem where users are reporting that the command is printing out the log file message like below even though the logs aren't even getting flushed.And I don't really get what's this
if-else
trying to accomplish within its logic comparison.Anyways, we will be replacing it and use
fs.existsSync(FILE_PATH)
to check whether a log file exists or not. So now, part of the code looks like this:This solution should be universal enough that it allows the command to flush the logs correctly even though a unique log path has been specified.