码迷,mamicode.com
首页 > 移动开发 > 详细

Android Log类基本用法

时间:2017-12-30 22:38:55      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:ast   strip   标签   logs   ati   real   throw   dev   eve   

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

Android Log类基本用法

标签:ast   strip   标签   logs   ati   real   throw   dev   eve   

原文地址:https://www.cnblogs.com/ywxt/p/android_logClass.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!