Skip to content

Commit 00c353c

Browse files
authored
Merge pull request #4517 from bvsubhash/namespace-logs
feat: print logs of a particular namespace
2 parents a016999 + acc2355 commit 00c353c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/API/LogManagement.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ module.exports = function(CLI) {
159159
// Get the list of all running apps
160160
that.Client.executeRemote('getMonitorData', {}, function(err, list) {
161161
var regexList = [];
162+
var namespaceList = [];
162163

163164
if (err) {
164165
Common.printError(err);
@@ -186,6 +187,21 @@ module.exports = function(CLI) {
186187
app_name : proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
187188
type : 'err'
188189
});
190+
} else if(proc.pm2_env && proc.pm2_env.namespace == id) {
191+
if(namespaceList.indexOf(proc.pm2_env.name) === -1) {
192+
namespaceList.push(proc.pm2_env.name)
193+
}
194+
if (proc.pm2_env.pm_out_log_path && exclusive !== 'err')
195+
pushIfUnique({
196+
path : proc.pm2_env.pm_out_log_path,
197+
app_name :proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
198+
type : 'out'});
199+
if (proc.pm2_env.pm_err_log_path && exclusive !== 'out')
200+
pushIfUnique({
201+
path : proc.pm2_env.pm_err_log_path,
202+
app_name : proc.pm2_env.pm_id + '|' + proc.pm2_env.name,
203+
type : 'err'
204+
});
189205
}
190206
// Populate the array `files_list` with the paths of all files we need to tail, when log in put is a regex
191207
else if(proc.pm2_env && (isNaN(id) && id[0] === '/' && id[id.length - 1] === '/')) {
@@ -233,6 +249,11 @@ module.exports = function(CLI) {
233249
Log.stream(that.Client, id, raw, timestamp, exclusive, highlight);
234250
})
235251
}
252+
else if(namespaceList.length > 0) {
253+
namespaceList.forEach(function(id) {
254+
Log.stream(that.Client, id, raw, timestamp, exclusive, highlight);
255+
})
256+
}
236257
else {
237258
Log.stream(that.Client, id, raw, timestamp, exclusive, highlight);
238259
}

lib/binaries/CLI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ commander.command('reloadLogs')
864864
//
865865
// Log streaming
866866
//
867-
commander.command('logs [id|name]')
867+
commander.command('logs [id|name|namespace]')
868868
.option('--json', 'json log output')
869869
.option('--format', 'formated log output')
870870
.option('--raw', 'raw output')

0 commit comments

Comments
 (0)