Skip to content

Commit

Permalink
log 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 cf46337 commit c9d81a8
Showing 1 changed file with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ public class LocalGcdHelper {
private static final String GCLOUD = "gcloud";
private static final Path INSTALLED_GCD_PATH;
private static final String GCD_VERSION_PREFIX = "gcd-emulator ";
private static final String CONTENTION_ERROR_MESSAGE =
"com.google.apphosting.client.serviceapp.RpcException: " +
"too much contention on these datastore entities. please try again.";

static {
INSTALLED_GCD_PATH = installedGcdPath();
Expand Down Expand Up @@ -217,6 +214,7 @@ public void run() {
try {
boolean readerDone = false;
boolean errorReaderDone = false;
String currentLog = null;
while (!readerDone || !errorReaderDone) {
if (!readerDone && reader.ready()) {
readerDone = reader.readLine() != null;
Expand All @@ -226,12 +224,7 @@ public void run() {
if (errorOutput == null) {
errorReaderDone = true;
} else {
if (errorOutput.startsWith("INFO:")
|| errorOutput.startsWith("com.google.apphosting.client.serviceapp")) {
if (!errorOutput.startsWith(CONTENTION_ERROR_MESSAGE)) {
System.err.println(errorOutput);
}
}
currentLog = processLog(errorOutput, currentLog);
}
}
}
Expand All @@ -240,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: ")) {
currentLog = 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 c9d81a8

Please sign in to comment.