Log類介紹: API for sending log output.Generally, use the __Log.v() Log.d() Log.i() Log.w() and Log.e()__ methods. The order in terms of verbosity, from l ...
Log類介紹:
API for sending log output.Generally, use the Log.v() Log.d() Log.i() Log.w() and Log.e() methods.
The order in terms of verbosity, from least to most is ERROR, WARN, INFO, DEBUG, VERBOSE.
Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime.
Error, warning and info logs are always kept.
Tip:
A good convention is to declare a
TAG
constant in your class:private static final String TAG = "MyActivity";
and use that in subsequent calls to the log methods.Tip:
Don't forget that when you make a call like
Log.v(TAG, "index=" + i);
that when you're building the string to pass into Log.d, the compiler uses a StringBuilder and at least three allocations occur: the StringBuilder itself, the buffer, and the String object.Realistically, there is also another buffer allocation and copy, and even more pressure on the gc. That means that if your log message is filtered out, you might be doing significant work and incurring significant overhead.
Log類位於android.util
包中,裡面都是一些靜態方法。
預設的輸出使用Log類就可以了。
Log類的幾個重要方法
1. Log.v()
v,即Verbose,中文:詳細的,輸出最最普通的信息。
兩重載:
public static int v(String tag, String msg)
public static int v(String tag, String msg, Throwable tr)
tag為標簽,一般為調用類的名稱,msg為輸出信息,其他輸出方法類似。
2.Log.d()
d,即Debug,輸出調試信息。
3.Log.i()
i,即Information,輸出一般信息。
4.Log.w()
w,即Warning,警告信息。
5.Log.e()
e,即Error,輸出錯誤信息。