From 583a1edc4aafb021f8f79d73dcc126da43560cef Mon Sep 17 00:00:00 2001 From: Kurt Partridge Date: Thu, 23 Aug 2012 22:45:23 -0700 Subject: [PATCH] [Rlog22] ResearchLogger fixed debug printing Change-Id: I2c59983236c936b8698004db8213b68c2f964cd5 --- .../android/inputmethod/research/LogUnit.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/java/src/com/android/inputmethod/research/LogUnit.java b/java/src/com/android/inputmethod/research/LogUnit.java index 884ade06b..27c4027de 100644 --- a/java/src/com/android/inputmethod/research/LogUnit.java +++ b/java/src/com/android/inputmethod/research/LogUnit.java @@ -24,10 +24,12 @@ import android.view.inputmethod.CompletionInfo; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; +import com.android.inputmethod.latin.Utils; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.research.ResearchLogger.LogStatement; import java.io.IOException; +import java.io.StringWriter; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -95,6 +97,22 @@ import java.util.Map; */ public synchronized void publishTo(final ResearchLog researchLog, final boolean isIncludingPrivateData) { + // Prepare debugging output if necessary + final StringWriter debugStringWriter; + final JsonWriter debugJsonWriter; + if (DEBUG) { + debugStringWriter = new StringWriter(); + debugJsonWriter = new JsonWriter(debugStringWriter); + debugJsonWriter.setIndent(" "); + try { + debugJsonWriter.beginArray(); + } catch (IOException e) { + Log.e(TAG, "Could not open array in JsonWriter", e); + } + } else { + debugStringWriter = null; + debugJsonWriter = null; + } final int size = mLogStatementList.size(); // Write out any logStatement that passes the privacy filter. for (int i = 0; i < size; i++) { @@ -110,6 +128,23 @@ import java.util.Map; final JsonWriter jsonWriter = researchLog.getValidJsonWriterLocked(); outputLogStatementToLocked(jsonWriter, mLogStatementList.get(i), mValuesList.get(i), mTimeList.get(i)); + if (DEBUG) { + outputLogStatementToLocked(debugJsonWriter, mLogStatementList.get(i), + mValuesList.get(i), mTimeList.get(i)); + } + } + if (DEBUG) { + try { + debugJsonWriter.endArray(); + debugJsonWriter.flush(); + } catch (IOException e) { + Log.e(TAG, "Could not close array in JsonWriter", e); + } + final String bigString = debugStringWriter.getBuffer().toString(); + final String[] lines = bigString.split("\n"); + for (String line : lines) { + Log.d(TAG, line); + } } }