Skip to content

Commit

Permalink
[fix] Break apart cli.logs to support forever logs and `forever log…
Browse files Browse the repository at this point in the history
…s <script|index>` correctly
  • Loading branch information
indexzero committed Dec 23, 2011
1 parent 72f4d14 commit 2815f71
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ forever.restart = function (target, format) {
}

if (proc.command) {
restartCommand.push('-c', command);
restartCommand.push('-c', proc.command);
}

if (proc.outFile) {
Expand Down
49 changes: 25 additions & 24 deletions lib/forever/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,32 +357,10 @@ app.cmd('clear :key', cli.clear = function (key) {

//
// ### function logs (target)
// #### @target {string} **Optional** Target script or index to list logs for
// Displays the logs using `tail` for the specified `target`. If no `target` is
// specified then it will display log files for all running forever processes.
// #### @target {string} Target script or index to list logs for
// Displays the logs using `tail` for the specified `target`.
//
app.cmd('logs :index', cli.logs = function (index) {
//
// Helper function for listing all log files
//
function listFiles() {
var index = 0,
rows = [[' ', 'script', 'logfile']];

forever.list(false, function (err, processes) {
forever.log.info('Logs for running Forever processes');
rows = rows.concat(processes.map(function (proc) {
return ['[' + index++ + ']', proc.file.grey, proc.logFile.magenta];
}));

cliff.putRows('data', rows, ['white', 'grey', 'magenta']);
});
}

if (typeof index === 'undefined') {
return listFiles();
}

forever.tail(index, function (err, logs) {
if (err) {
return forever.log.error(err.message);
Expand All @@ -397,6 +375,29 @@ app.cmd('logs :index', cli.logs = function (index) {
});
});

//
// ### function logFiles ()
// Display log files for all running forever processes.
//
app.cmd('logs', cli.logFiles = function (index) {
if (typeof index !== 'undefined') {
return;
}

var rows = [[' ', 'script', 'logfile']];
index = 0;

forever.list(false, function (err, processes) {
forever.log.info('Logs for running Forever processes');
rows = rows.concat(processes.map(function (proc) {
return ['[' + index++ + ']', proc.file.grey, proc.logFile.magenta];
}));

cliff.putRows('data', rows, ['white', 'grey', 'magenta']);
});
});


app.cmd('columns add :name', cli.addColumn = function (name) {
if (checkColumn(name)) {
var columns = forever.config.get('columns');
Expand Down

0 comments on commit 2815f71

Please sign in to comment.