Retain blank lines in log stream
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
What's going wrong?
Currently, if any process tries to log a blank line (i.e. \n\n), the line is removed in streaming logs yet retained in the log file and in the tail function.
The Log.*stream methods in lib/API/Log.js are checking for general falsiness of each element after splitting a chunk on \n, presumably to remove the resulting last element that will be an empty string (since the methods print a newline at the end of input anyway). Unfortunately, since the chunk is split on \n, any two newlines in a row will result in an element that is an empty string. The log methods then will skip over the element - not printing anything - thereby missing the extra newline.
I submitted #3193 to fix this issue, but it was closed in lieu of 4f5566e. Unfortunately, that commit only reinforces the problem - any element with a length of zero (any empty string) would be passed over. In fact, any element with a length of 0 would also return false on the first test (!line), thereby making it redundant.
How could we reproduce this issue?
In any instance, try logging a blank line (console.log('foo\n\nbar')). If tailed, the log will produce the correct output:
0|test- | foo
0|test- |
0|test- | bar
... but when streaming, the newline will be eliminated:
0|test- | foo
0|test- | bar
Supporting information
$ pm2 report
===============================================================================
--- PM2 REPORT (Wed Oct 25 2017 13:54:38 GMT+0000 (UTC)) ----------------------
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 2.6.1
node version : 8.4.0
node path : undefined
argv : /home/ubuntu/.nvm/versions/node/v8.4.0/bin/node,/home/ubuntu/.nvm/versions/node/v8.4.0/lib/node_modules/pm2/lib/Daemon.js
argv0 : node
user : ubuntu
uid : 1000
gid : 1000
uptime : 8903min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 2.6.1
node version : 8.4.0
node path : /home/ubuntu/.nvm/versions/node/v8.4.0/bin/pm2
argv : /home/ubuntu/.nvm/versions/node/v8.4.0/bin/node,/home/ubuntu/.nvm/versions/node/v8.4.0/bin/pm2,report
argv0 : node
user : ubuntu
uid : 1000
gid : 1000
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : linux
type : Linux
cpus : Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
cpus nb : 1
freemem : 152821760
totalmem : 1039011840
home : /home/ubuntu
===============================================================================
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/API/Log.js and inspect the Log.*stream methods, then reproduce the issue with console.log('foo\n\nbar') and compare streaming output with the tail function. Done means streaming logs retain the blank line between foo and bar without losing the trailing-line handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli, observability
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100