You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
===============================================================================
The text was updated successfully, but these errors were encountered:
My bad i misunderstood the problem, if i understand correctly, the normal behavior should be to output even empty lines if both the logs and the streaming ?
@vmarchaud Correct, expected behavior is to print an empty line on both logs and streaming if one exists, i.e. if a chunk of log data contains \n\n. Currently this does happen in the trailing logs, but in streaming, the newline is omitted - any extra \ns beyond the first are removed.
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:... but when streaming, the newline will be eliminated:
Supporting information
The text was updated successfully, but these errors were encountered: