输出日志信息是指Android应用

输出日志信息是指Android应用运行时的信息,例如在运行的时候抛出异常,在Eclipse中的Console视图中是不能看到异常信息的。Android应用该如何调试和查看错误信息呢?于是Eclipse中的ADt插件就提供了一个 查看输出日志信息和方便软件工程师、程序员调试的一个试图LogCat。

总结:Android 第六课 查看输出日志信息 - 好有爱 - 什么都不写就更好了
 

 上面有很多信息。

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.

必须要创建一个过滤器,在LogCat视图中,根据tag来查询出当前的应用所输出的信息。

比如要输出www.baidu.com那应该怎么输出呢?

有两种方式:

1.System.out.println(www.baidu.com): 2.Log.i(TAG,www.baidu.com)

前者你可以再LogCat视图tag为System.out中搜索,就能够搜索到你想要的信息。

后者,LogCat视图tag必须为TAG所表示的字符串信息来查询。

 

个人学习后:

    觉得,这个学习很重要,因为以后做开发的话,肯定会用到调试的,这个道理你们都懂的。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章