Android之日志工具

日志工具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!");
    }
}

級別從低到高:

  • Log.v() 最為瑣碎的,意義最小的日志信息,對應級別verbose
  • Log.d() 打印調試信息,最常用,對應級別debug
  • Log.i() 打印比較重要的數據,可以幫助分析用戶行為數據,對應級別info
  • Log.w() 打印警告信息,此處有潛在危險,需要修復,對應級別warn
  • Log.e() 打印程序中的錯誤信息,,必須修復,對應級別error

注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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,923評論 18 139
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 173,269評論 25 708
  • Spring Boot 參考指南 介紹 轉載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 46,951評論 6 342
  • linux資料總章2.1 1.0寫的不好抱歉 但是2.0已經改了很多 但是錯誤還是無法避免 以后資料會慢慢更新 大...
    數據革命閱讀 12,218評論 2 33
  • 1字面意思:運行循環、跑圈,內部其實就是do-while循環,在這個循環內部不斷地處理各種事物,NSRunloop...
    rebeccaBull閱讀 186評論 0 0