Skip to content

Commit

Permalink
Log gcd.sh errors instead of printing to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajay Kannan committed Oct 14, 2015
1 parent 33ddb90 commit 235da5a
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,17 @@ public void run() {
try {
boolean readerDone = false;
boolean errorReaderDone = false;
String currentLog = null;
while (!readerDone || !errorReaderDone) {
if (!readerDone && reader.ready()) {
readerDone = reader.readLine() != null;
readerDone = reader.readLine() == null;
}
if (!errorReaderDone && errorReader.ready()) {
String errorOutput = errorReader.readLine();
if (errorOutput == null) {
errorReaderDone = true;
} else {
if (errorOutput.startsWith("SEVERE")) {
System.err.println(errorOutput);
}
currentLog = processLog(errorOutput, currentLog);
}
}
}
Expand All @@ -234,6 +233,27 @@ public void run() {
}
}

private static boolean isNewGcdLog(String line) {
return line.contains("com.google.apphosting.client.serviceapp.BaseApiServlet")
&& !line.trim().startsWith("at ");
}

private static String processLog(String currentLine, String currentLog) {
if (isNewGcdLog(currentLine)) {
if (currentLog != null) {
log.info(currentLog.trim());
}
return "GCD ";
} else if (currentLine.startsWith("SEVERE: ")) {
return null; // Don't show duplicate error messages from gcd.sh
} else if (currentLog != null && currentLine.startsWith("INFO: ")) {
return currentLog + currentLine.substring("INFO: ".length()) + "\n";
} else if (currentLog != null && !currentLine.trim().startsWith("at ")) {
return currentLog + currentLine + "\n";
}
return currentLog;
}

public static ProcessStreamReader start(
Process process, String blockUntil, boolean blockOnErrorStream) throws IOException {
ProcessStreamReader thread = new ProcessStreamReader(process, blockUntil, blockOnErrorStream);
Expand Down

0 comments on commit 235da5a

Please sign in to comment.