輸出日誌信息是指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所表示的字符串信息來查詢。

 

個人學習後:

    覺得,這個學習很重要,因爲以後做開發的話,肯定會用到調試的,這個道理你們都懂的。

 

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