zoukankan      html  css  js  c++  java
  • 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,输出错误信息。

  • 相关阅读:
    《从零开始学Swift》学习笔记(Day 45)——重写方法
    《从零开始学Swift》学习笔记(Day 44)——重写属性
    浅析Android中ndk-build支持的参数
    texstudio on ubuntu 12.04
    arm上的参数列表传递的分析(以android为例)
    编译错误
    native method与so中function的关联
    Java.lang.NoClassDefFoundError--找不到相应的类
    Sublime Text 3 文档
    JNI 函数注册与管理
  • 原文地址:https://www.cnblogs.com/ywxt/p/android_logClass.html
Copyright © 2011-2022 走看看