Android打印日志管理

做项目的时候,免不了要打印许多日志,等项目上线了,想要去除日志是又找不到在哪里怎么办?我们可以建立一个日志打印的类来统一管理;

public class LogUtil {
    public static final String TAG = "project name";
    public static boolean isDebug = true;
    public static boolean isInfo = true;
    public static boolean isWarn = true;
    public static boolean isError = true;

    public static void d(String tag, String msg) {
        if (isDebug)
            android.util.Log.d(tag, msg);
    }

    public static void d(String tag, String msg, Throwable t) {
        if (isDebug)
            android.util.Log.d(tag, msg, t);
    }

    public static void i(String tag, String msg) {
        if (isInfo)
            android.util.Log.i(tag, msg);
    }

    public static void i(String tag, String msg, Throwable t) {
        if (isInfo)
            android.util.Log.i(tag, msg, t);
    }

    public static void w(String tag, String msg) {
        if (isWarn)
            android.util.Log.w(tag, msg);
    }

    public static void w(String tag, String msg, Throwable t) {
        if (isWarn)
            android.util.Log.w(tag, msg, t);
    }

    public static void e(String tag, String msg) {
        if (isError)
            android.util.Log.e(tag, msg);
    }

    public static void e(String tag, String msg, Throwable t) {
        if (isError)
            android.util.Log.e(tag, msg, t);
    }
    public static void isDebugAll(boolean isTure){
        isDebug=isTure;
        isInfo = isTure;
        isWarn = isTure;
        isError = isTure;
    }
}
原文地址:https://www.cnblogs.com/jiayaguang/p/4371453.html