Android Log类基本用法

弓背霞明剑照霜,秋风走马出咸阳。这篇文章主要讲述Android Log类基本用法相关的知识,希望能为你提供帮助。

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.
【Android Log类基本用法】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,输出错误信息。

    推荐阅读