Android Log類基本用法

來源:互聯網
上載者:User

標籤: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類基本用法

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.