Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retain blank lines in log stream #3237

Open
shanehughes3 opened this issue Oct 25, 2017 · 4 comments
Open

Retain blank lines in log stream #3237

shanehughes3 opened this issue Oct 25, 2017 · 4 comments

Comments

@shanehughes3
Copy link

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
===============================================================================
@vmarchaud
Copy link
Contributor

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 ?

@mogita
Copy link

mogita commented Oct 31, 2017

Noticed the same issue just now. I used a \n to separate blocks of logs, but the output didn't work as expected. +1 for retaining blank lines.

@shanehughes3
Copy link
Author

@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.

@kentnek
Copy link

kentnek commented Apr 7, 2021

Is there any update on this? I also want to see the blank lines in my app's beautifully crafted logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants