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

Fix bug with namespace when logs command run before start #5789

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions lib/API/LogManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ module.exports = function(CLI) {
// Get the list of all running apps
that.Client.executeRemote('getMonitorData', {}, function(err, list) {
var regexList = [];
var namespaceList = [];

if (err) {
Common.printError(err);
Expand Down Expand Up @@ -190,9 +189,6 @@ module.exports = function(CLI) {
type : 'err'
});
} else if(proc.pm2_env && proc.pm2_env.namespace == id) {
if(namespaceList.indexOf(proc.pm2_env.name) === -1) {
namespaceList.push(proc.pm2_env.name)
}
if (proc.pm2_env.pm_out_log_path && exclusive !== 'err')
pushIfUnique({
path : proc.pm2_env.pm_out_log_path,
Expand Down Expand Up @@ -251,12 +247,8 @@ module.exports = function(CLI) {
Log.stream(that.Client, id, raw, timestamp, exclusive, highlight);
})
}
else if(namespaceList.length > 0) {
namespaceList.forEach(function(id) {
Log.stream(that.Client, id, raw, timestamp, exclusive, highlight);
})
}
else {
// Internally Log.stream handles `id` being a name, id, or namespace just fine
Log.stream(that.Client, id, raw, timestamp, exclusive, highlight);
}
});
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/logs/log-namespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ LOG_PATH_PREFIX="${SRC}/__log-namespace__"
rm -rf "${LOG_PATH_PREFIX}"
mkdir "${LOG_PATH_PREFIX}"

# The first operation that starts the daemon needs to be in the foreground, otherwise we risk starting multiple
$pm2 ping

LOG_FILE_PREMATURE="${LOG_PATH_PREFIX}/premature-log-out.log"
$pm2 logs e2e-test-log-namespace > $LOG_FILE_PREMATURE & # backgrounded - will be stopped by `$pm2 delete all`

$pm2 start echo.js --namespace e2e-test-log-namespace

LOG_FILE_BASELINE="${LOG_PATH_PREFIX}/baseline-out.log"
Expand All @@ -20,6 +26,8 @@ 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"
grep -q "tick" ${LOG_FILE_PREMATURE}
spec "Should have 'tick' in the log file even if 'log' called before 'start'"

LOG_FILE_LINES_ZERO="${LOG_PATH_PREFIX}/lines-zero-out.log"
$pm2 logs e2e-test-log-namespace --lines 0 > $LOG_FILE_LINES_ZERO &
Expand Down
Loading