Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/API/LogManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/Daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
21 changes: 17 additions & 4 deletions lib/God/ActionMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/ProcessContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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...');
});
}
});
Expand Down
12 changes: 11 additions & 1 deletion lib/binaries/CLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -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
Expand Down