安卓學習筆記----Android Studio中日誌打印和Logcat簡單使用教程

1. 簡單介紹:

安卓中打印日誌的方法有5中,分別爲:
1.Log.v() - VERBOSE
2.Log.d() - DEBUG
3.Log.i()- INFO
4.Log.w()- WARN
5.Log.e()- ERROR

強度從上至下遞增

Log部分源碼和常量解釋:

/**
     * Priority constant for the println method; use Log.v.
     */
    public static final int VERBOSE = 2;

    /**
     * Priority constant for the println method; use Log.d.
     */
    public static final int DEBUG = 3;

    /**
     * Priority constant for the println method; use Log.i.
     */
    public static final int INFO = 4;

    /**
     * Priority constant for the println method; use Log.w.
     */
    public static final int WARN = 5;

    /**
     * Priority constant for the println method; use Log.e.
     */
    public static final int ERROR = 6;

    /**
     * Priority constant for the println method.
     */
    public static final int ASSERT = 7;
2. Logcat簡單使用教程

第一步:定義TAG,即日誌的標籤,建議使用類名+XX的形式,容易找到日誌的打印地點,也不會和系統的日誌混淆

private static final String TAG = "MainActivityLog";

然後在需要寫上日誌的地方調用Log方法,舉個栗子

Log.d(TAG,"onCreate()方法被調用");

第二步:點擊圖中框的位置,箭頭指向的選項是默認的
在這裏插入圖片描述
第三步:打開下拉菜單,選擇 Edit filter Configuration選項
在這裏插入圖片描述
第四步:點擊+,填寫Tag的值,就是剛剛在第一步設置的那個,選擇ok
在這裏插入圖片描述
最後:下拉框選擇剛剛自己設置的過濾器,Logcat就只會打印你所設置的日誌內容了
在這裏插入圖片描述

發佈了27 篇原創文章 · 獲贊 49 · 訪問量 2252
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章