1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package io.flutter; 6 7 import android.support.annotation.NonNull; 8 9 import io.flutter.BuildConfig; 10 11 /** 12 * Port of {@link android.util.Log} that only logs in {@link BuildConfig#DEBUG} mode and 13 * internally filters logs based on a {@link #logLevel}. 14 */ 15 public class Log { 16 private static int logLevel = android.util.Log.DEBUG; 17 18 /** 19 * Sets a log cutoff such that a log level of lower priority than {@code logLevel} is 20 * filtered out. 21 * <p> 22 * See {@link android.util.Log} for log level constants. 23 */ setLogLevel(int logLevel)24 public static void setLogLevel(int logLevel) { 25 Log.logLevel = logLevel; 26 } 27 v(@onNull String tag, @NonNull String message)28 public static void v(@NonNull String tag, @NonNull String message) { 29 if (BuildConfig.DEBUG && logLevel <= android.util.Log.VERBOSE) { 30 android.util.Log.v(tag, message); 31 } 32 } 33 v(@onNull String tag, @NonNull String message, @NonNull Throwable tr)34 public static void v(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) { 35 if (BuildConfig.DEBUG && logLevel <= android.util.Log.VERBOSE) { 36 android.util.Log.v(tag, message, tr); 37 } 38 } 39 i(@onNull String tag, @NonNull String message)40 public static void i(@NonNull String tag, @NonNull String message) { 41 if (BuildConfig.DEBUG && logLevel <= android.util.Log.INFO) { 42 android.util.Log.i(tag, message); 43 } 44 } 45 i(@onNull String tag, @NonNull String message, @NonNull Throwable tr)46 public static void i(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) { 47 if (BuildConfig.DEBUG && logLevel <= android.util.Log.INFO) { 48 android.util.Log.i(tag, message, tr); 49 } 50 } 51 d(@onNull String tag, @NonNull String message)52 public static void d(@NonNull String tag, @NonNull String message) { 53 if (BuildConfig.DEBUG && logLevel <= android.util.Log.DEBUG) { 54 android.util.Log.d(tag, message); 55 } 56 } 57 d(@onNull String tag, @NonNull String message, @NonNull Throwable tr)58 public static void d(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) { 59 if (BuildConfig.DEBUG && logLevel <= android.util.Log.DEBUG) { 60 android.util.Log.d(tag, message, tr); 61 } 62 } 63 w(@onNull String tag, @NonNull String message)64 public static void w(@NonNull String tag, @NonNull String message) { 65 android.util.Log.w(tag, message); 66 } 67 w(@onNull String tag, @NonNull String message, @NonNull Throwable tr)68 public static void w(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) { 69 android.util.Log.w(tag, message, tr); 70 } 71 e(@onNull String tag, @NonNull String message)72 public static void e(@NonNull String tag, @NonNull String message) { 73 android.util.Log.e(tag, message); 74 } 75 e(@onNull String tag, @NonNull String message, @NonNull Throwable tr)76 public static void e(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) { 77 android.util.Log.e(tag, message, tr); 78 } 79 wtf(@onNull String tag, @NonNull String message)80 public static void wtf(@NonNull String tag, @NonNull String message) { 81 android.util.Log.wtf(tag, message); 82 } 83 wtf(@onNull String tag, @NonNull String message, @NonNull Throwable tr)84 public static void wtf(@NonNull String tag, @NonNull String message, @NonNull Throwable tr) { 85 android.util.Log.wtf(tag, message, tr); 86 } 87 } 88