未验证 提交 6d2d9c88 编写于 作者: M Matt Carroll 提交者: GitHub

Resolves embedding log chattyness by gating verbose, debug, and info logs by...

Resolves embedding log chattyness by gating verbose, debug, and info logs by level (#34876). (#9425)

上级 fa16babc
......@@ -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.
* <p>
* 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);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册