Add logger indent option and indent nested xcode command outputs (#7867)

* Add indent option to logger and indent non-flutter nested output

* Add a missed override

* Formatting
This commit is contained in:
xster 2017-02-08 18:27:47 -08:00 committed by GitHub
parent 83a4cf269f
commit 1cc78145fe
4 changed files with 49 additions and 13 deletions

View File

@ -3,7 +3,7 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert' show ASCII;
import 'dart:convert' show ASCII, LineSplitter;
import 'package:stack_trace/stack_trace.dart';
@ -29,7 +29,10 @@ abstract class Logger {
/// Display normal output of the command. This should be used for things like
/// progress messages, success messages, or just normal command output.
void printStatus(String message, { bool emphasis: false, bool newline: true, String ansiAlternative });
void printStatus(
String message,
{ bool emphasis: false, bool newline: true, String ansiAlternative, int indent }
);
/// Use this for verbose tracing output. Users can turn this output on in order
/// to help diagnose issues with the toolchain or with their setup.
@ -66,13 +69,18 @@ class StdoutLogger extends Logger {
}
@override
void printStatus(String message, { bool emphasis: false, bool newline: true, String ansiAlternative }) {
void printStatus(
String message,
{ bool emphasis: false, bool newline: true, String ansiAlternative, int indent }
) {
_status?.cancel();
_status = null;
if (terminal.supportsColor && ansiAlternative != null)
message = ansiAlternative;
if (emphasis)
message = terminal.bolden(message);
if (indent != null && indent > 0)
message = LineSplitter.split(message).map((String line) => ' ' * indent + line).join('\n');
if (newline)
message = '$message\n';
stdout.write(message);
@ -114,7 +122,10 @@ class BufferLogger extends Logger {
void printError(String message, [StackTrace stackTrace]) => _error.writeln(message);
@override
void printStatus(String message, { bool emphasis: false, bool newline: true, String ansiAlternative }) {
void printStatus(
String message,
{ bool emphasis: false, bool newline: true, String ansiAlternative, int indent }
) {
if (newline)
_status.writeln(message);
else
@ -147,7 +158,10 @@ class VerboseLogger extends Logger {
}
@override
void printStatus(String message, { bool emphasis: false, bool newline: true, String ansiAlternative }) {
void printStatus(
String message,
{ bool emphasis: false, bool newline: true, String ansiAlternative, int indent }
) {
_emit(_LogType.status, message);
}

View File

@ -680,7 +680,10 @@ class NotifyingLogger extends Logger {
}
@override
void printStatus(String message, { bool emphasis: false, bool newline: true, String ansiAlternative }) {
void printStatus(
String message,
{ bool emphasis: false, bool newline: true, String ansiAlternative, int indent }
) {
_messageController.add(new LogMessage('status', message));
}
@ -762,7 +765,10 @@ class _AppRunLogger extends Logger {
}
@override
void printStatus(String message, { bool emphasis: false, bool newline: true, String ansiAlternative }) {
void printStatus(
String message,
{ bool emphasis: false, bool newline: true, String ansiAlternative, int indent }
) {
if (logToStdout) {
print(message);
} else {

View File

@ -26,8 +26,19 @@ void printError(String message, [StackTrace stackTrace]) => logger.printError(me
///
/// If `ansiAlternative` is provided, and the terminal supports color, that
/// string will be printed instead of the message.
void printStatus(String message, { bool emphasis: false, bool newline: true, String ansiAlternative }) {
logger.printStatus(message, emphasis: emphasis, newline: newline, ansiAlternative: ansiAlternative);
///
/// If `indent` is provided, each line of the message will be prepended by the specified number of
/// whitespaces.
void printStatus(
String message,
{ bool emphasis: false, bool newline: true, String ansiAlternative, int indent }) {
logger.printStatus(
message,
emphasis: emphasis,
newline: newline,
ansiAlternative: ansiAlternative,
indent: indent
);
}
/// Use this for verbose tracing output. Users can turn this output on in order

View File

@ -166,10 +166,15 @@ Future<XcodeBuildResult> buildXcodeProject({
);
if (result.exitCode != 0) {
if (result.stderr.isNotEmpty)
printStatus(result.stderr);
if (result.stdout.isNotEmpty)
printStatus(result.stdout);
printStatus('Failed to build iOS app');
if (result.stderr.isNotEmpty) {
printStatus('Error output from Xcode build:\n');
printStatus(result.stderr, indent: 4);
}
if (result.stdout.isNotEmpty) {
printStatus('Xcode\'s output:\n');
printStatus(result.stdout, indent: 4);
}
return new XcodeBuildResult(
success: false,
stdout: result.stdout,