From 6d2d9c88fc06491c34d8df2d8f5a4489fb812c53 Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Fri, 21 Jun 2019 16:40:32 -0700 Subject: [PATCH] Resolves embedding log chattyness by gating verbose, debug, and info logs by level (#34876). (#9425) --- shell/platform/android/io/flutter/Log.java | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/shell/platform/android/io/flutter/Log.java b/shell/platform/android/io/flutter/Log.java index a4696c96e..1cfa51ff9 100644 --- a/shell/platform/android/io/flutter/Log.java +++ b/shell/platform/android/io/flutter/Log.java @@ -9,41 +9,54 @@ import android.support.annotation.NonNull; import io.flutter.BuildConfig; /** - * Port of {@link android.util.Log} that only logs in {@link BuildConfig#DEBUG} mode. + * Port of {@link android.util.Log} that only logs in {@link BuildConfig#DEBUG} mode and + * internally filters logs based on a {@link #logLevel}. */ public class Log { + private static int logLevel = android.util.Log.DEBUG; + + /** + * Sets a log cutoff such that a log level of lower priority than {@code logLevel} is + * filtered out. + *

+ * See {@link android.util.Log} for log level constants. + */ + public static void setLogLevel(int logLevel) { + Log.logLevel = logLevel; + } + public static void v(@NonNull String tag, @NonNull String message) { - if (BuildConfig.DEBUG) { + if (BuildConfig.DEBUG && logLevel >= android.util.Log.VERBOSE) { android.util.Log.v(tag, message); } } public static void v(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) { - if (BuildConfig.DEBUG) { + if (BuildConfig.DEBUG && logLevel >= android.util.Log.VERBOSE) { android.util.Log.v(tag, message, tr); } } public static void i(@NonNull String tag, @NonNull String message) { - if (BuildConfig.DEBUG) { + if (BuildConfig.DEBUG && logLevel >= android.util.Log.INFO) { android.util.Log.i(tag, message); } } public static void i(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) { - if (BuildConfig.DEBUG) { + if (BuildConfig.DEBUG && logLevel >= android.util.Log.INFO) { android.util.Log.i(tag, message, tr); } } public static void d(@NonNull String tag, @NonNull String message) { - if (BuildConfig.DEBUG) { + if (BuildConfig.DEBUG && logLevel >= android.util.Log.DEBUG) { android.util.Log.d(tag, message); } } public static void d(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) { - if (BuildConfig.DEBUG) { + if (BuildConfig.DEBUG && logLevel >= android.util.Log.DEBUG) { android.util.Log.d(tag, message, tr); } } -- GitLab