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

feat: print logs of a particular namespace #4517

Merged
merged 1 commit into from Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/API/LogManagement.js
Expand Up @@ -159,6 +159,7 @@ 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 @@ -186,6 +187,21 @@ module.exports = function(CLI) {
app_name : proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
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,
app_name :proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
type : 'out'});
if (proc.pm2_env.pm_err_log_path && exclusive !== 'out')
pushIfUnique({
path : proc.pm2_env.pm_err_log_path,
app_name : proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
type : 'err'
});
}
// Populate the array `files_list` with the paths of all files we need to tail, when log in put is a regex
else if(proc.pm2_env && (isNaN(id) && id[0] === '/' && id[id.length - 1] === '/')) {
Expand Down Expand Up @@ -233,6 +249,11 @@ 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 {
Log.stream(that.Client, id, raw, timestamp, exclusive, highlight);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/binaries/CLI.js
Expand Up @@ -864,7 +864,7 @@ commander.command('reloadLogs')
//
// Log streaming
//
commander.command('logs [id|name]')
commander.command('logs [id|name|namespace]')
.option('--json', 'json log output')
.option('--format', 'formated log output')
.option('--raw', 'raw output')
Expand Down