开始利用零碎时间做android开发了,android中android.util.Log到底怎么要用呢?跟Java中的日志有什么区别呢?首先看下Log的源码

public final class Log {    /**     * Priority constant for the println method; use Log.v.     */    public static final int VERBOSE = 2;    /**     * Priority constant for the println method; use Log.d.     */    public static final int DEBUG = 3;    /**     * Priority constant for the println method; use Log.i.     */    public static final int INFO = 4;    /**     * Priority constant for the println method; use Log.w.     */    public static final int WARN = 5;    /**     * Priority constant for the println method; use Log.e.     */    public static final int ERROR = 6;    /**     * Priority constant for the println method.     */    public static final int ASSERT = 7;....................................}

发现他共有6种级别,数字大的代表级别高,在代码中可以通过直接写日志的方式在logcat中查看,

5个常用的为Log.v() ,Log.d() ,Log.i() ,Log.w(),Log.e()

同时在记录日志的时候注意Log中的一个方法,看源码

   /**     * Checks to see whether or not a log for the specified tag is loggable at the specified level.     *     *  The default level of any tag is set to INFO. This means that any level above and including     *  INFO will be logged. Before you make any calls to a logging method you should check to see     *  if your tag should be logged. You can change the default level by setting a system property:     *      'setprop log.tag.<YOUR_LOG_TAG> <LEVEL>'     *  Where level is either VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT, or SUPPRESS. SUPPRESS will     *  turn off all logging for your tag. You can also create a local.prop file that with the     *  following in it:     *      'log.tag.<YOUR_LOG_TAG>=<LEVEL>'     *  and place that in /data/local.prop.     *     * @param tag The tag to check.     * @param level The level to check.     * @return Whether or not that this is allowed to be logged.     * @throws IllegalArgumentException is thrown if the tag.length() > 23.     */    public static native boolean isLoggable(String tag, int level);
具体的使用看doc

更多相关文章

  1. 通话距离感应实现源码
  2. android 多点触控实例源码
  3. android 微博客户端源码
  4. android源码分享之蓝虫火车票余票查询源码
  5. Android 文件浏览器源码
  6. Android ShutdownThread.java源码分析
  7. android 结合源码深入剖析AsyncTask机制原理
  8. Android源码分析之WindowManager.LayoutParams属性更新过程

随机推荐

  1. IT兄弟连 JavaWeb教程 文件上传技术
  2. 读取Excel文件并跳过空行但不是空列
  3. Spring MVC-集成(Integration)-集成LOG4J示
  4. 有关JavaScript的认识
  5. Java将一个字符串中的多个连一起的空格变
  6. Java提高篇——equals()方法和“==”运算
  7. javascript 基础知识点
  8. 关于Javascript中声明变量、函数的笔记
  9. 如何在Spring Data(JPA)派生查询中按多个属
  10. Java设计模式-策略模式