LogUtil工具类

步骤一:新建LogUtil类

public class LogUtil {

private static int LOGLEVEL =10;

private final static int VERBOSE =1;

private final static int DEBUG =2;

private final static int INFO =3;

private final static int WARN =4;

private final static int ERROR =5;

private static StringTAG ="";

/**

    * @param loglevel

    */

    public static void setDebug(boolean isDebug) {

if (isDebug) {

LOGLEVEL =10;

}else {

LOGLEVEL =0;

}

}

public static void setTag(String tag) {

TAG = tag;

}

public static void v(String tag, String msg) {

if (LOGLEVEL >VERBOSE)

Log.v(TAG, tag +"====" + msg);

}

public static void d(String tag, String msg) {

if (LOGLEVEL >DEBUG)

Log.d(TAG, tag +"====" + msg);

}

public static void i(String tag, String msg) {

if (LOGLEVEL >INFO)

Log.i(TAG, tag +"====" + msg);

}

public static void w(String tag, String msg) {

if (LOGLEVEL >WARN)

Log.w(TAG, tag +"====" + msg);

}

public static void e(String tag, String msg) {

if (LOGLEVEL >ERROR)

Log.e(TAG, tag +"====" + msg);

}

}

步骤二:在Application类的onCreate()方法里调用

LogUtil.setTag(getPackageName());// 设置LogTag

使用举例:LogUtil.e("系统版本", "1.0");

你可能感兴趣的:(LogUtil工具类)