android.util.Log常用的方法有以下5個:Log.v() Log.d() Log.i() Log.w() 以及 Log.e() 。根據首字母對應VERBOSE,DEBUG,INFO, WARN,ERROR。
1、Log.v 的調試顏色為黑色的,任何消息都會輸出,這里的v代表verbose啰嗦的意思,平時使用就是Log.v("","");
2、Log.d的輸出顏色是藍色的,僅輸出debug調試的意思,但他會輸出上層的信息,過濾起來可以通過DDMS的Logcat標簽來選擇.
3、Log.i的輸出為綠色,一般提示性的消息information,它不會輸出Log.v和Log.d的信息,但會顯示i、w和e的信息
4、Log.w的意思為橙色,可以看作為warning警告,一般需要我們注意優化Android代碼,同時選擇它后還會輸出Log.e的信息。
5、Log.e為紅色,可以想到error錯誤,這里僅顯示紅色的錯誤信息,這些錯誤就需要我們認真的分析,查看棧的信息了。
注意:不同的打印方法在使用時都是某個方法帶上(String tag, String msg)參數,tag表示的是打印信息的標簽,msg表示的是需要打印的信息。
package com.example.demo;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.util.Log;
public class MainActivity extends Activity {
final static String TAG="LOGCAT";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.v(TAG,"verbose");
Log.d(TAG,"Debug");
Log.i(TAG,"Info");
Log.w(TAG,"Warn");
Log.e(TAG,"Error");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}

