Loading services/net/java/android/net/util/SharedLog.java +11 −3 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.net.util; import android.annotation.NonNull; import android.annotation.Nullable; import android.text.TextUtils; import android.util.LocalLog; import android.util.Log; Loading Loading @@ -92,10 +93,17 @@ public class SharedLog { } /** * Log an error due to an exception, with the exception stacktrace. * Log an error due to an exception, with the exception stacktrace if provided. * * <p>The error and exception message appear in the shared log, but the stacktrace is only * logged in general log output (logcat). */ public void e(@NonNull String msg, @NonNull Throwable e) { Log.e(mTag, record(Category.ERROR, msg + ": " + e.getMessage()), e); public void e(@NonNull String msg, @Nullable Throwable exception) { if (exception == null) { e(msg); return; } Log.e(mTag, record(Category.ERROR, msg + ": " + exception.getMessage()), exception); } public void i(String msg) { Loading tests/net/java/android/net/util/SharedLogTest.java +5 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,8 @@ public class SharedLogTest { final SharedLog logLevel2a = logTop.forSubComponent("twoA"); final SharedLog logLevel2b = logTop.forSubComponent("twoB"); logLevel2b.e("2b or not 2b"); logLevel2b.e("No exception", null); logLevel2b.e("Wait, here's one", new Exception("Test")); logLevel2a.w("second post?"); final SharedLog logLevel3 = logLevel2a.forSubComponent("three"); Loading @@ -54,6 +56,9 @@ public class SharedLogTest { final String[] expected = { " - MARK first post!", " - [twoB] ERROR 2b or not 2b", " - [twoB] ERROR No exception", // No stacktrace in shared log, only in logcat " - [twoB] ERROR Wait, here's one: Test", " - [twoA] WARN second post?", " - still logging", " - [twoA.three] 3 >> 2", Loading Loading
services/net/java/android/net/util/SharedLog.java +11 −3 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.net.util; import android.annotation.NonNull; import android.annotation.Nullable; import android.text.TextUtils; import android.util.LocalLog; import android.util.Log; Loading Loading @@ -92,10 +93,17 @@ public class SharedLog { } /** * Log an error due to an exception, with the exception stacktrace. * Log an error due to an exception, with the exception stacktrace if provided. * * <p>The error and exception message appear in the shared log, but the stacktrace is only * logged in general log output (logcat). */ public void e(@NonNull String msg, @NonNull Throwable e) { Log.e(mTag, record(Category.ERROR, msg + ": " + e.getMessage()), e); public void e(@NonNull String msg, @Nullable Throwable exception) { if (exception == null) { e(msg); return; } Log.e(mTag, record(Category.ERROR, msg + ": " + exception.getMessage()), exception); } public void i(String msg) { Loading
tests/net/java/android/net/util/SharedLogTest.java +5 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,8 @@ public class SharedLogTest { final SharedLog logLevel2a = logTop.forSubComponent("twoA"); final SharedLog logLevel2b = logTop.forSubComponent("twoB"); logLevel2b.e("2b or not 2b"); logLevel2b.e("No exception", null); logLevel2b.e("Wait, here's one", new Exception("Test")); logLevel2a.w("second post?"); final SharedLog logLevel3 = logLevel2a.forSubComponent("three"); Loading @@ -54,6 +56,9 @@ public class SharedLogTest { final String[] expected = { " - MARK first post!", " - [twoB] ERROR 2b or not 2b", " - [twoB] ERROR No exception", // No stacktrace in shared log, only in logcat " - [twoB] ERROR Wait, here's one: Test", " - [twoA] WARN second post?", " - still logging", " - [twoA.three] 3 >> 2", Loading