diff --git a/lib/API/LogManagement.js b/lib/API/LogManagement.js index cdfbef157..793bbf307 100644 --- a/lib/API/LogManagement.js +++ b/lib/API/LogManagement.js @@ -121,6 +121,23 @@ module.exports = function(CLI) { }); }; + /** + * Same as reloadLogs but without console outputs. + * @method reloadLogsSilently + * @return + */ + CLI.prototype.reloadLogsSilently = function(cb) { + var that = this; + + that.Client.executeRemote('reloadLogsSilently', {}, function(err, logs) { + if (err) { + Common.printError(err); + return cb ? cb(Common.retErr(err)) : that.exitCli(cst.ERROR_EXIT); + } + return cb ? cb(null, logs) : that.exitCli(cst.SUCCESS_EXIT); + }); + }; + /** * Description * @method streamLogs diff --git a/lib/Daemon.js b/lib/Daemon.js index d47ef6a8d..2c0d83275 100644 --- a/lib/Daemon.js +++ b/lib/Daemon.js @@ -247,7 +247,8 @@ Daemon.prototype.innerStart = function(cb) { ping : God.ping, getVersion : God.getVersion, getReport : God.getReport, - reloadLogs : God.reloadLogs + reloadLogs : God.reloadLogs, + reloadLogsSilently : God.reloadLogsSilently, }); this.startLogic(); diff --git a/lib/God/ActionMethods.js b/lib/God/ActionMethods.js index f84b40fa1..3f41de230 100644 --- a/lib/God/ActionMethods.js +++ b/lib/God/ActionMethods.js @@ -607,24 +607,26 @@ module.exports = function(God) { * Description * @method reloadLogs * @param {} opts - * @param {} cb + * @param {Boolean} opts.silent If true, the command won't ouput messages to the console. + * @param {Function} cb * @return CallExpression */ God.reloadLogs = function(opts, cb) { - console.log('Reloading logs...'); + const { silent } = opts || {} + if (!silent) console.log('Reloading logs...'); var processIds = Object.keys(God.clusters_db); processIds.forEach(function (id) { var cluster = God.clusters_db[id]; - console.log('Reloading logs for process id %d', id); + if (!silent) console.log('Reloading logs for process id %d', id); if (cluster && cluster.pm2_env) { // Cluster mode if (cluster.send && cluster.pm2_env.exec_mode == 'cluster_mode') { try { cluster.send({ - type:'log:reload' + type: silent ? 'log:reloadSilently' : 'log:reload' }); } catch(e) { console.error(e.message || e); @@ -642,6 +644,17 @@ module.exports = function(God) { return cb(null, {}); }; + /** + * Same as reloadLogs but without console outputs. + * @method reloadLogsSilently + * @param {} opts + * @param {Function} cb + * @return CallExpression + */ + God.reloadLogsSilently = function(opts, cb) { + return God.reloadLogs({ silent: true }, cb) + }; + /** * Send Line To Stdin * @method sendLineToStdin diff --git a/lib/ProcessContainer.js b/lib/ProcessContainer.js index fb2e57c34..b90d36135 100644 --- a/lib/ProcessContainer.js +++ b/lib/ProcessContainer.js @@ -120,7 +120,7 @@ function exec(script, stds) { } process.on('message', function (msg) { - if (msg.type === 'log:reload') { + if (['log:reload', 'log:reloadSilently'].includes(msg.type)) { for (var k in stds){ if (typeof stds[k] == 'object' && !isNaN(stds[k].fd)){ if (stds[k].destroy) stds[k].destroy(); @@ -132,7 +132,7 @@ function exec(script, stds) { Utility.startLogging(stds, function (err) { if (err) return console.error('Failed to reload logs:', err.stack); - console.log('Reloading log...'); + if (msg.type !== 'log:reloadSilently') console.log('Reloading log...'); }); } }); diff --git a/lib/binaries/CLI.js b/lib/binaries/CLI.js index 05eeae9c4..18abb0f26 100644 --- a/lib/binaries/CLI.js +++ b/lib/binaries/CLI.js @@ -879,6 +879,16 @@ commander.command('reloadLogs') pm2.reloadLogs(); }); +// +// Reload all logs but silently. +// When using the CLI, this is equivalent to pm2 reloadLogs -s (or --silent). +// +commander.command('reloadLogsSilently') + .description('reload all logs silently') + .action(function() { + pm2.reloadLogsSilently(); + }); + // // Log streaming // @@ -1022,7 +1032,7 @@ commander.command('examples') // Catch all // commander.command('*') - .action(function() { + .action(function(cmd) { console.log(cst.PREFIX_MSG_ERR + chalk.bold('Command not found\n')); displayUsage(); // Check if it does not forget to close fds from RPC