From acc2355cac9d7fc15f33f064867802dc403dbbb9 Mon Sep 17 00:00:00 2001 From: Subhash Date: Sat, 23 Nov 2019 13:46:27 +0530 Subject: [PATCH] feat: print logs of a particular namespace pm2 logs --- lib/API/LogManagement.js | 21 +++++++++++++++++++++ lib/binaries/CLI.js | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/API/LogManagement.js b/lib/API/LogManagement.js index dd5d3f0dd..531f50269 100644 --- a/lib/API/LogManagement.js +++ b/lib/API/LogManagement.js @@ -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); @@ -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] === '/')) { @@ -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); } diff --git a/lib/binaries/CLI.js b/lib/binaries/CLI.js index 430a05296..e60a858f1 100644 --- a/lib/binaries/CLI.js +++ b/lib/binaries/CLI.js @@ -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')