diff --git a/lib/API/Log.js b/lib/API/Log.js index 7156e2e36..35aae46c5 100644 --- a/lib/API/Log.js +++ b/lib/API/Log.js @@ -98,9 +98,11 @@ Log.stream = function(Client, id, raw, timestamp, exclusive, highlight) { var min_padding = 3 bus.on('log:*', function(type, packet) { - if (id !== 'all' - && packet.process.name != id - && packet.process.pm_id != id) + var isMatchingProcess = id === 'all' + || packet.process.name === id + || packet.process.pm_id === id + || packet.process.namespace === id; + if (!isMatchingProcess) return; if ((type === 'out' && exclusive === 'err') diff --git a/test/e2e.sh b/test/e2e.sh index d70015e78..77b26d434 100644 --- a/test/e2e.sh +++ b/test/e2e.sh @@ -92,6 +92,7 @@ runTest ./test/e2e/logs/log-entire.sh runTest ./test/e2e/logs/log-null.sh runTest ./test/e2e/logs/log-json.sh runTest ./test/e2e/logs/log-create-not-exist-dir.sh +runTest ./test/e2e/logs/log-namespace.sh # MODULES runTest ./test/e2e/modules/get-set.sh diff --git a/test/e2e/logs/log-namespace.sh b/test/e2e/logs/log-namespace.sh new file mode 100644 index 000000000..9e2b20357 --- /dev/null +++ b/test/e2e/logs/log-namespace.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +SRC=$(cd $(dirname "$0"); pwd) +source "${SRC}/../include.sh" + +cd $file_path/log-namespace/ + +LOG_PATH_PREFIX="${SRC}/__log-namespace__" + +rm -rf "${LOG_PATH_PREFIX}" +mkdir "${LOG_PATH_PREFIX}" + +$pm2 start echo.js --namespace e2e-test-log-namespace + +LOG_FILE_BASELINE="${LOG_PATH_PREFIX}/baseline-out.log" +$pm2 logs e2e-test-log-namespace > $LOG_FILE_BASELINE & # backgrounded - will be stopped by `$pm2 delete all` + +sleep 2 # should leave time for ~40 "tick" lines + +# Using -q to avoid spamming, since there will be a fair few "tick" matches +grep -q "tick" ${LOG_FILE_BASELINE} +spec "Should have 'tick' in the log file" + +LOG_FILE_LINES_ZERO="${LOG_PATH_PREFIX}/lines-zero-out.log" +$pm2 logs e2e-test-log-namespace --lines 0 > $LOG_FILE_LINES_ZERO & + +sleep 2 # should leave time for ~40 "tick" lines + +# Using -q to avoid spamming, since there will be a fair few "tick" matches +grep -q "tick" ${LOG_FILE_LINES_ZERO} +spec "Should have 'tick' in the log file even if using --lines 0" + +cd ${SRC} +rm -rf "${LOG_PATH_PREFIX}" +$pm2 delete all diff --git a/test/fixtures/log-namespace/echo.js b/test/fixtures/log-namespace/echo.js new file mode 100644 index 000000000..a916f7dc5 --- /dev/null +++ b/test/fixtures/log-namespace/echo.js @@ -0,0 +1,4 @@ +console.log("start"); +setInterval(function () { + console.log("tick"); +}, 50);