Loading core/java/com/android/internal/logging/LogBuilder.java +20 −3 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.view.View; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; /** * Helper class to assemble more complex logs. * Loading @@ -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) { Loading Loading @@ -97,7 +105,11 @@ public class LogBuilder { throw new IllegalArgumentException( "Value must be loggable type - int, long, float, String"); } 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; } Loading Loading @@ -198,6 +210,11 @@ 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; } Loading core/java/com/android/internal/logging/MetricsLogger.java +0 −3 Original line number Diff line number Diff line Loading @@ -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); } Loading core/tests/coretests/src/com/android/internal/logging/LogBuilderTest.java +11 −1 Original line number Diff line number Diff line Loading @@ -114,4 +114,14 @@ public class LogBuilderTest extends TestCase { assertEquals(10, out[1]); } public void testGiantLogOmitted() { LogBuilder badBuilder = new LogBuilder(0); StringBuilder b = new StringBuilder(); for (int i = 0; i < 4000; i++) { b.append("test, " + i); } badBuilder.addTaggedData(100, b.toString()); assertTrue(badBuilder.serialize().length < LogBuilder.MAX_SERIALIZED_SIZE); } } Loading
core/java/com/android/internal/logging/LogBuilder.java +20 −3 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.view.View; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; /** * Helper class to assemble more complex logs. * Loading @@ -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) { Loading Loading @@ -97,7 +105,11 @@ public class LogBuilder { throw new IllegalArgumentException( "Value must be loggable type - int, long, float, String"); } 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; } Loading Loading @@ -198,6 +210,11 @@ 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; } Loading
core/java/com/android/internal/logging/MetricsLogger.java +0 −3 Original line number Diff line number Diff line Loading @@ -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); } Loading
core/tests/coretests/src/com/android/internal/logging/LogBuilderTest.java +11 −1 Original line number Diff line number Diff line Loading @@ -114,4 +114,14 @@ public class LogBuilderTest extends TestCase { assertEquals(10, out[1]); } public void testGiantLogOmitted() { LogBuilder badBuilder = new LogBuilder(0); StringBuilder b = new StringBuilder(); for (int i = 0; i < 4000; i++) { b.append("test, " + i); } badBuilder.addTaggedData(100, b.toString()); assertTrue(badBuilder.serialize().length < LogBuilder.MAX_SERIALIZED_SIZE); } }