2019-05-29 20:19:29 -07:00
|
|
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package io.flutter;
|
|
|
|
|
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
|
|
|
|
|
import io.flutter.BuildConfig;
|
|
|
|
|
|
|
|
|
|
/**
|
2019-06-21 16:40:32 -07:00
|
|
|
* Port of {@link android.util.Log} that only logs in {@link BuildConfig#DEBUG} mode and
|
|
|
|
|
* internally filters logs based on a {@link #logLevel}.
|
2019-05-29 20:19:29 -07:00
|
|
|
*/
|
|
|
|
|
public class Log {
|
2019-06-21 16:40:32 -07:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-29 20:19:29 -07:00
|
|
|
public static void v(@NonNull String tag, @NonNull String message) {
|
2019-06-24 23:03:42 -07:00
|
|
|
if (BuildConfig.DEBUG && logLevel <= android.util.Log.VERBOSE) {
|
2019-05-29 20:19:29 -07:00
|
|
|
android.util.Log.v(tag, message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void v(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) {
|
2019-06-24 23:03:42 -07:00
|
|
|
if (BuildConfig.DEBUG && logLevel <= android.util.Log.VERBOSE) {
|
2019-05-29 20:19:29 -07:00
|
|
|
android.util.Log.v(tag, message, tr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void i(@NonNull String tag, @NonNull String message) {
|
2019-06-24 23:03:42 -07:00
|
|
|
if (BuildConfig.DEBUG && logLevel <= android.util.Log.INFO) {
|
2019-05-29 20:19:29 -07:00
|
|
|
android.util.Log.i(tag, message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void i(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) {
|
2019-06-24 23:03:42 -07:00
|
|
|
if (BuildConfig.DEBUG && logLevel <= android.util.Log.INFO) {
|
2019-05-29 20:19:29 -07:00
|
|
|
android.util.Log.i(tag, message, tr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void d(@NonNull String tag, @NonNull String message) {
|
2019-06-24 23:03:42 -07:00
|
|
|
if (BuildConfig.DEBUG && logLevel <= android.util.Log.DEBUG) {
|
2019-05-29 20:19:29 -07:00
|
|
|
android.util.Log.d(tag, message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void d(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) {
|
2019-06-24 23:03:42 -07:00
|
|
|
if (BuildConfig.DEBUG && logLevel <= android.util.Log.DEBUG) {
|
2019-05-29 20:19:29 -07:00
|
|
|
android.util.Log.d(tag, message, tr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void w(@NonNull String tag, @NonNull String message) {
|
|
|
|
|
android.util.Log.w(tag, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void w(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) {
|
|
|
|
|
android.util.Log.w(tag, message, tr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void e(@NonNull String tag, @NonNull String message) {
|
|
|
|
|
android.util.Log.e(tag, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void e(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) {
|
|
|
|
|
android.util.Log.e(tag, message, tr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void wtf(@NonNull String tag, @NonNull String message) {
|
|
|
|
|
android.util.Log.wtf(tag, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void wtf(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) {
|
|
|
|
|
android.util.Log.wtf(tag, message, tr);
|
|
|
|
|
}
|
|
|
|
|
}
|