Android之日志工具

2017-08-02  本文已影响0人  天涯笑笑生

日志工具Log(android.util.Log),共有五个方法打印日志

package android.util;

public final class Log {
    public static final int ASSERT = 7;
    public static final int DEBUG = 3;
    public static final int ERROR = 6;
    public static final int INFO = 4;
    public static final int VERBOSE = 2;
    public static final int WARN = 5;

    Log() {
        throw new RuntimeException("Stub!");
    }

    public static int v(String tag, String msg) {
        throw new RuntimeException("Stub!");
    }

    public static int v(String tag, String msg, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static int d(String tag, String msg) {
        throw new RuntimeException("Stub!");
    }

    public static int d(String tag, String msg, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static int i(String tag, String msg) {
        throw new RuntimeException("Stub!");
    }

    public static int i(String tag, String msg, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static int w(String tag, String msg) {
        throw new RuntimeException("Stub!");
    }

    public static int w(String tag, String msg, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static native boolean isLoggable(String var0, int var1);

    public static int w(String tag, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static int e(String tag, String msg) {
        throw new RuntimeException("Stub!");
    }

    public static int e(String tag, String msg, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static int wtf(String tag, String msg) {
        throw new RuntimeException("Stub!");
    }

    public static int wtf(String tag, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static int wtf(String tag, String msg, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static String getStackTraceString(Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static int println(int priority, String tag, String msg) {
        throw new RuntimeException("Stub!");
    }
}

级别从低到高:

注1:tag 参数一般为当前的类名,msg想打印的具体信息

 private String tag = MainActivity.class.getSimpleName();

    /**
    * Activity 被创建时
    */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Log.d(tag, "onCreate");
    }

注2:System.out.println(),虽然在eclipse中输入syso,按下代码提示键就会出来,但在Android studio中不支持这种快捷方式。打印日志的的优点:可以添加过滤器、有等级区分、打印可控制、有打印时等。
注3:快捷输入,如输入logd,然后点击tab键,就会补全。
在onCreate()外面输入logt,点击tab,就会以当前的类名作为值生成一个TAG常量

private static final String TAG = "MainActivity";

注4:添加过滤器,选择显示级别,搜索等等

图片.png
上一篇 下一篇

猜你喜欢

热点阅读