Android開發(fā)筆記之:Log圖文詳解(Log.v,Log.d,Log.i,Log.w,Log.e)
在Android群里,經(jīng)常會有人問我,Android Log是怎么用的,今天我就把從網(wǎng)上以及SDK里東拼西湊過來,讓大家先一睹為快,希望對大家入門Android Log有一定的幫助.
android.util.Log常用的方法有以下5個:Log.v() Log.d() Log.i() Log.w() 以及 Log.e() 。根據(jù)首字母對應(yīng)VERBOSE,DEBUG,INFO, WARN,ERROR。
1、Log.v 的調(diào)試顏色為黑色的,任何消息都會輸出,這里的v代表verbose啰嗦的意思,平時使用就是Log.v("","");
2、Log.d的輸出顏色是藍(lán)色的,僅輸出debug調(diào)試的意思,但他會輸出上層的信息,過濾起來可以通過DDMS的Logcat標(biāo)簽來選擇.
3、Log.i的輸出為綠色,一般提示性的消息information,它不會輸出Log.v和Log.d的信息,但會顯示i、w和e的信息
4、Log.w的意思為橙色,可以看作為warning警告,一般需要我們注意優(yōu)化Android代碼,同時選擇它后還會輸出Log.e的信息。
5、Log.e為紅色,可以想到error錯誤,這里僅顯示紅色的錯誤信息,這些錯誤就需要我們認(rèn)真的分析,查看棧的信息了。
下面是我做的一個簡單的LogDemo(Step By Step):
Step 1:準(zhǔn)備工作(打開LogCat視窗).
啟動Eclipse,在Window->Show View會出來一個對話框,當(dāng)我們點擊Ok按鈕時,會在控制臺窗口出現(xiàn)LogCat視窗.如下圖:
Step 2:新建一個Android工程,命名為LogDemo.
Step 3:設(shè)計UI界面,我們在這里就加了一個Button按鈕(點擊按鈕出現(xiàn)Log日志信息).
Main.xml代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Presse Me Look Log"
/>
</LinearLayout>
Step 4:設(shè)計主類LogDemo.java,代碼如下:
package com.android.test;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class LogDemo extends Activity {
private static final String ACTIVITY_TAG="LogDemo";
private Button bt;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//通過findViewById找到Button資源
bt = (Button)findViewById(R.id.bt);
//增加事件響應(yīng)
bt.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
Log.v(LogDemo.ACTIVITY_TAG, "This is Verbose.");
Log.d(LogDemo.ACTIVITY_TAG, "This is Debug.");
Log.i(LogDemo.ACTIVITY_TAG, "This is Information");
Log.w(LogDemo.ACTIVITY_TAG, "This is Warnning.");
Log.e(LogDemo.ACTIVITY_TAG, "This is Error.");
}
});
}
}
Step 5:運行LogDemo工程,效果如下:
當(dāng)我們點擊按鈕時,會觸發(fā)事件,在Logcat視窗下有如下效果:
- Android系統(tǒng)開發(fā)中l(wèi)og的使用方法及簡單的原理
- android輕松管理安卓應(yīng)用中的log日志 發(fā)布應(yīng)用時log日志全部去掉的方法
- android雜記:C++文件的添加log方法分享
- Android將應(yīng)用調(diào)試log信息保存在SD卡的方法
- Android編程之基于Log演示一個activity生命周期實例詳解
- Android 實現(xiàn)自己的LOG信息
- microlog4android將Android Log日志寫到SD卡文件中實現(xiàn)方法
- Android 日志工具(log)的使用方法
- Android開發(fā)實現(xiàn)的Log統(tǒng)一管理類
相關(guān)文章
Android ListView 單條刷新方法實踐及原理解析
這篇文章主要介紹了Android ListView 單條刷新方法實踐及原理解析的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-07-07Android實現(xiàn)調(diào)用攝像頭拍照與視頻功能
這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)調(diào)用攝像頭拍照與視頻功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-04-04RecyclerView通過GridLayoutManager實現(xiàn)多樣式布局的示例
本篇文章主要介紹了RecyclerView通過GridLayoutManager實現(xiàn)多樣式布局的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-12-12大型項目里Flutter測試應(yīng)用實例集成測試深度使用詳解
這篇文章主要為大家介紹了大型項目里Flutter測試應(yīng)用實例集成測試深度使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12Android通過json向MySQL中讀寫數(shù)據(jù)的方法詳解【寫入篇】
這篇文章主要介紹了Android通過json向MySQL中讀寫數(shù)據(jù)的方法,結(jié)合實例形式較為詳細(xì)的分析了Android json類的定義、調(diào)用及php接收json數(shù)據(jù)并寫入mysql的實現(xiàn)技巧,需要的朋友可以參考下2016-06-06Android AIDL中Map參數(shù)傳遞的問題詳解
這篇文章主要給大家介紹了關(guān)于Android AIDL中Map參數(shù)傳遞問題的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友下面來一起看看吧。2017-12-12