diff options
| author | Alison Cichowlas <asc@google.com> | 2017-01-19 09:47:17 -0500 |
|---|---|---|
| committer | Alison Cichowlas <asc@google.com> | 2017-01-23 18:36:59 -0500 |
| commit | 38c4680aae03be539c7adc64697c5c65a54d6d48 (patch) | |
| tree | 545e910ab2fbe504b05c3603efbc176f7a4c2310 /core/java | |
| parent | a2feb80b83a679b9c297a42b0631431f44112a73 (diff) | |
Tron - Omit overlong lines and warn when doing so.
Test: updated LogBuilderTest
Change-Id: I0218acfacca53598a546cea5b3adeecd0d639031
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/com/android/internal/logging/LogBuilder.java | 23 | ||||
| -rw-r--r-- | core/java/com/android/internal/logging/MetricsLogger.java | 3 |
2 files changed, 20 insertions, 6 deletions
diff --git a/core/java/com/android/internal/logging/LogBuilder.java b/core/java/com/android/internal/logging/LogBuilder.java index 7eda3da70bba..2d78979b4c03 100644 --- a/core/java/com/android/internal/logging/LogBuilder.java +++ b/core/java/com/android/internal/logging/LogBuilder.java @@ -23,6 +23,7 @@ import android.view.View; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; + /** * Helper class to assemble more complex logs. * @@ -31,6 +32,13 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; public class LogBuilder { private static final String TAG = "LogBuilder"; + + // Min required eventlog line length. + // See: android/util/cts/EventLogTest.java + // Size checks enforced here are intended only as sanity checks; + // your logs may be truncated earlier. Please log responsibly. + public static final int MAX_SERIALIZED_SIZE = 4000; + private SparseArray<Object> entries = new SparseArray(); public LogBuilder(int mainCategory) { @@ -97,7 +105,11 @@ public class LogBuilder { throw new IllegalArgumentException( "Value must be loggable type - int, long, float, String"); } - entries.put(tag, value); + if (value.toString().getBytes().length > MAX_SERIALIZED_SIZE) { + Log.i(TAG, "Log value too long, omitted: " + value.toString()); + } else { + entries.put(tag, value); + } return this; } @@ -198,18 +210,23 @@ public class LogBuilder { out[i * 2] = entries.keyAt(i); out[i * 2 + 1] = entries.valueAt(i); } + int size = out.toString().getBytes().length; + if (size > MAX_SERIALIZED_SIZE) { + Log.i(TAG, "Log line too long, did not emit: " + size + " bytes."); + throw new RuntimeException(); + } return out; } public void deserialize(Object[] items) { int i = 0; - while(i < items.length) { + while (i < items.length) { Object key = items[i++]; Object value = i < items.length ? items[i++] : null; if (key instanceof Integer) { entries.put((Integer) key, value); } else { - Log.i(TAG, "Invalid key " + key.toString()); + Log.i(TAG, "Invalid key " + key.toString()); } } } diff --git a/core/java/com/android/internal/logging/MetricsLogger.java b/core/java/com/android/internal/logging/MetricsLogger.java index 16c2719c0584..b90336c442aa 100644 --- a/core/java/com/android/internal/logging/MetricsLogger.java +++ b/core/java/com/android/internal/logging/MetricsLogger.java @@ -94,9 +94,6 @@ public class MetricsLogger { } public static void action(LogBuilder content) { - //EventLog.writeEvent(524292, content.serialize()); - // Below would be the *right* way to do this, using the generated - // EventLogTags method, but that doesn't work. if (content.getType() == MetricsEvent.TYPE_UNKNOWN) { content.setType(MetricsEvent.TYPE_ACTION); } |
