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.

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,输出错误信息。

转载于:https://www.cnblogs.com/ywxt/p/android_logClass.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值