美文网首页
LogUtil工具类

LogUtil工具类

作者: 小婷婷tt | 来源:发表于2018-05-16 13:57 被阅读0次

步骤一:新建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工具类

      本文链接:https://www.haomeiwen.com/subject/grypdftx.html