Android Log工具类,获取当前方法名称

 Log工具类

/**
 * 作者:created by meixi
 * 邮箱:[email protected]
 * 日期:2019/4/17 10
 */
public class LgqLogutil {

    private static boolean ifShow=true;


    public static void setIfShow(boolean b){
        ifShow = b;
    }


    public static void i(String string){
        StackTraceElement[] s = Thread.currentThread().getStackTrace();
        String methodName = s[3].getMethodName();
        if (ifShow)
        Log.i("lgq",methodName+"----"+string);
    }

    public static void e(String string){
        StackTraceElement[] s = Thread.currentThread().getStackTrace();
        String methodName = s[3].getMethodName();
        if (ifShow)
            Log.e("lgq",methodName+"----"+string);
    }

}

获取当前方法名称:

 代码:

        StackTraceElement[] s = Thread.currentThread().getStackTrace();
        String methodName = s[3].getMethodName();
        LgqLogutil.i(methodName);
//        LgqLogutil.setIfShow(false);
        LgqLogutil.e(methodName);

04-17 10:22:43.521 20009-20009/? I/lgq: onResume----callActivityOnResume
04-17 10:22:43.522 20009-20009/? E/lgq: onResume----callActivityOnResume

猜你喜欢

转载自blog.csdn.net/meixi_android/article/details/89350421
今日推荐