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就只會打印你所設置的日誌內容了