Skip to content

Commit

Permalink
Merge pull request #4517 from bvsubhash/namespace-logs
Browse files Browse the repository at this point in the history
feat: print logs of a particular namespace
  • Loading branch information
Unitech committed Apr 12, 2020
2 parents a016999 + acc2355 commit 00c353c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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

0 comments on commit 00c353c

Please sign in to comment.