Skip to content

Commit

Permalink
feat(ui): add ability to output to stderr
Browse files Browse the repository at this point in the history
closes #218
- add stderr option to log method
- change error method to output most things to stderr rather than stdout
  • Loading branch information
acburdine committed Jun 26, 2017
1 parent f052df6 commit 86a9eeb
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ class UI {
});
}

log(message, color) {
log(message, color, stderr) {
if (color) {
message = chalk[color](message);
}

this.stdout.write(`${this.spinner ? '\r' : ''}${message}\n`);
let stream = stderr ? 'stderr' : 'stdout';

this[stream].write(`${this.spinner ? '\r' : ''}${message}\n`);
}

success(message) {
Expand Down Expand Up @@ -157,7 +159,7 @@ class UI {
let verboseOutput = error.toString(true);

// Log the verbose error if verbose is set, otherwise log the non-verbose error output
this.log(this.verbose ? verboseOutput : error.toString(false));
this.log(this.verbose ? verboseOutput : error.toString(false), null, true);
this.log(debugInfo, 'yellow');

if (error.logToFile()) {
Expand All @@ -168,7 +170,7 @@ class UI {
let output = `An error occurred.\n${chalk.yellow('Message:')} '${error.message}'\n\n`;

if (!this.verbose) {
this.log(output, 'red');
this.log(output, 'red', true);
}

if (error.stack) {
Expand All @@ -184,17 +186,17 @@ class UI {
}

if (this.verbose) {
this.log(output, 'red');
this.log(output, 'red', true);
}

this.log(debugInfo, 'yellow');
this._logErrorToFile(`${debugInfo}\n${output}`);
} else if (isObject(error)) {
// TODO: find better way to handle object errors?
this.log(JSON.stringify(error));
this.log(JSON.stringify(error), null, true);
} else if (error !== false) {
// If the error is false, we're just exiting (makes the promise chains easier)
this.log('An unknown error occured.');
this.log('An unknown error occured.', null, true);
}
}

Expand Down

0 comments on commit 86a9eeb

Please sign in to comment.