精华内容
下载资源
问答
  • Log.isLoggable的使用测试样例
  • 什么是isLoggableisLoggable是android.util.Log提供的方法,用于检查指定Log的TAG的level是否满足打印条件,如满足则返回true反之则返回false。 源码中关于isLoggable的注释 isLoggable在源码中的注释如下: /** ...
    什么是isLoggable?

    isLoggable是android.util.Log提供的方法,用于检查指定Log的TAG的level是否满足打印条件,如满足则返回true反之则返回false。

    源码中关于isLoggable的注释

    isLoggable在源码中的注释如下:

    /**     
    * 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);
    
    使用注意
    1. isLoggable默认level为android.util.Log.INFO;

    2. 只有 level >= INFO才能输出,即level >= INFO时isLoggable返回true,反之则返回false;

    展开全文
  • Log.isLoggable使用方式

    2018-04-26 16:32:49
    使用Log.isLoggable可以方便的开关log,但是这个方法具体的用法很多人都不知道. 谷歌注释如下: public static boolean isLoggable(String tag,  int level) Checks to see whether or not a log for the specified...

    使用Log.isLoggable可以方便的开关log,但是这个方法具体的用法很多人都不知道.

    谷歌注释如下:

    public static boolean isLoggable(String tag,
                                     int level)
    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.
    Parameters:
    tag - The tag to check.
    level - The level to check.
    Returns:
    Whether or not that this is allowed to be logged.
    Throws:

    IllegalArgumentException - is thrown if the tag.length() > 23 for Nougat (7.0) releases (API <= 23) and prior, there is no tag limit of concern after this API level.

    这个方法返回一个boolean值,代码里用这个boolean值做判断是否打印log即可.

    手机上使用设置prop的方法来动态修改这个boolean.

     

    比如我声明的boolean值如下:

    static final boolean DEBUG = Log.isLoggable("DozeService", Log.DEBUG);
    

    手机上想让这个值变为true的话,用如下的命令即可

    adb shell setprop log.tag.DozeService D

     

     

     

     

    展开全文
  • Log.isLoggable的使用

    千次阅读 2018-06-04 19:06:47
    本文将介绍怎么打印出framework源码中的log。 在Android源码中,经常可以看到如下的log代码: //AudioService.java ...protected static final boolean DEBUG_VOL = Log.isLoggable(TAG + &quot;.V...

    本文将介绍怎么打印出framework源码中的log。


    在Android源码中,经常可以看到如下的log代码:

    //AudioService.java
    
    private static final String TAG = "AudioService";
    protected static final boolean DEBUG_VOL = Log.isLoggable(TAG + ".VOL", Log.DEBUG);
    
    private void adjustStreamVolume(int streamType, int direction, int flags,
            String callingPackage, String caller, int uid) {
    ......
        if (DEBUG_VOL) Log.d(TAG, "adjustStreamVolume() stream=" + streamType + ", dir=" + direction
                    + ", flags=" + flags + ", caller=" + caller);
    ......
    }
    

    只有在Log.isLoggable返回值为true的时候,adjustStreamVolume()的log才能正常输出。那怎样才能让isLoggable才会返回true呢?


    #定义
    isLoggable()在源码中定义如下

    /** 
    * 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);  
    

    从定义可知:

    1. isLoggable默认level为Log.INFO;
    2. 只有 level >= INFO才能输出,即level >= INFO时isLoggable返回true,反之则返回false;
    3. 可以通过setprop log.tag.<YOUR_LOG_TAG> 来改变log的默认level,如adb shell setprop log.tag.AudioService.VOL D。也可以将这些属性按照log.tag.AudioService.VOL = D的形式,写入/data/local.prop中;
    4. tag的长度如果超过23个字符则会抛出IllegalArgumentException异常;

    #使用方法

    protected static final boolean DEBUG_VOL = Log.isLoggable(TAG + ".VOL", Log.DEBUG);
    

    因为DEBUG是static的变量,所以当Log类被加载时,其值就已经设置好了。如果要使得isLoggable返回为true,那么setprop需要在Log类被加载前设置好,因此使用setprop之后需要重启对应的进程,framework属于每一个进程,那如何重启framework呢?可以使用:

    adb shell stop  
    adb shell start 
    

    所以
    方法一(机器重启后失效):
    在串口中输入

    setprop log.tag.AudioService.VOL D
    stop
    start
    

    方法二(机器重启仍生效):
    将log.tag.AudioService.VOL = D加入到/data/local.prop文件中。


    后续发现加个persist关键字,重启也能生效

    setprop persist.log.tag.AudioService.VOL D
    
    展开全文
  • Android Log.isLoggable

    2018-08-06 22:35:31
    Log.isLoggable API中关于此方法的说明: 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...

    Log.isLoggable

    API中关于此方法的说明:

    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. ’ 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.=’ and place that in /data/local.prop.

    Log.isLoggable()的默认log级别是INFO,像级别低一些的DEBUG和VERBOSE的log就直接被过滤掉了。使用此API,我们可以实现按需求控制log打印:

    在正式版本中,像一些DEBUG和VERBOSE的log不会被打印出来,减少了系统打印的log数量

    在我们平时调试的时候,可以手动设置log输出级别,

    所有应用都采用同样的过滤方式,比设置boolean变量控制方便

    final String TAG = "Test";
    Log.v(TAG, "verbose is active: " + Log.isLoggable(TAG, Log.VERBOSE));
    Log.d(TAG, "debug is active: " + Log.isLoggable(TAG, Log.DEBUG));
    Log.i(TAG, "info is active: " + Log.isLoggable(TAG, Log.INFO));
    Log.w(TAG, "warn is active: " + Log.isLoggable(TAG, Log.WARN));
    Log.e(TAG, "error is active: " + Log.isLoggable(TAG, Log.ERROR));

    输出

    VERBOSE/Test(598): verbose is active: false
    DEBUG/Test(598): debug is active: false
    INFO/Test(598): info is active: true
    WARN/Test(598): warn is active: true
    ERROR/Test(598): error is active: true

    法的信息可以看出,有2种方式可以修改log过滤级别

    • setprop
    adb root
    
    adb shell setprop log.tag.TAG VERBOSE
    
    //在我们的开发板子上面,直接在串口下面输入setprop log.tag.TAG VERBOSE,注意,TAG是我们自己定义的TAG名称

    但大多數log都不適用,因為它們是在boot時就決定是否要印出log,而此property性質在重開機後就消失

    • 利用local.prop

    在linux上,vim local.prop,並寫入 log.tag.TAG=VERBOSE (TAG為依據framework上所設定的TAG, = 要加)

    adb root
    adb remount
    adb push local.prop /data/local.prop
    adb shell chmod 644 /data/local.prop
    adb shell chown root.root /data/local.prop
    adb reboot
    //在开发版上面,直接cp文件到/data
    cp XXX/local.prop /data
    chmod 644 /data/local.prop
    chown root.root /data/local.prop
    reboot

    参考如下:
    http://www.dotblogs.com.tw/kent2480/archive/2014/03/21/144467.aspx
    http://stackoverflow.com/questions/7948204/does-log-isloggable-returns-wrong-values

    展开全文
  • 近来发现源码里面好多地方用到了 Log.isLoggable , 一查一看,是个东西,适合系统层以及root 主板设备上使用,能实现动态开关 android.util.Log.isLoggable(TAG, android.util.Log.DEBUG) 如上面代码以及文档说明...
  • Log.isLoggable之二源码解析

    千次阅读 2017-06-05 20:11:57
    简介上一篇文章Log.isLoggable之一正确的使用姿势讲了Log.isLoggable使用,本文就来讲讲isLoggable的源码实现。Log.isLoggable源码分析首先,来看看Log.java中isLoggable的实现。通过源码我们可以知道isLoggable是一...
  • Android中Log等级分为一下几种: private static final String ...private boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE); private boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private boolean INFO ...
  • android Log.isLoggable使用

    2017-05-17 23:46:11
    android 动态控制logcat日志开关,通过Log.isLoggable(TAG,level)方法动态控制。 此API可以实现不更换APK,在出问题的手机上就直接能抓到有效log,能提升不少工作效率。 该方法说明:/** * Checks to see ...
  • isLoggable是什么  在Android源码中,我们经常可以看到如下代码: [java] view plain copy   //packages/apps/InCallUI/src/com/android/incallui/Log.java    public static ...
  • android Log.isLoggable方法的使用 android 动态控制logcat日志开关,通过Log.isLoggable(TAG,level)方法动态控制,1.添加日志的时候加入判断, String TAG="Volley"; boolean isDbug=Log.isLoggable(TAG, Log....
  • android Log.isLoggable方法的使用 android 动态控制logcat日志开关,通过Log.isLoggable(TAG,level)方法动态控制, 1.添加日志的时候加入判断, String TAG="Volley"; boolean isDbug=Log....
  • android Log.isLoggable方法的使用 android 动态控制logcat日志开关,通过Log.isLoggable(TAG,level)方法动态控制, 1.添加日志的时候加入判断,  String TAG="Volley";  boolean isDbug=Log.isLoggable...
  • 在前一篇文章《Android 5.0 如何正确启用isLoggable(一)__使用详解》中分析了isLoggable的使用方法,本文主要分析isLoggable实现原理以及user版系统root后永久enable isLoggable的原理,并使用脚本自动设置...
  • private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); 然后查看一些资料,发现这个还比较实用。 Log.isLoggable的定义: isLoggable是android.util.Log提供的方法,用于检查指定TAG的等级,...
  • 在上文《Android5.0 如何正确启用isLoggable(一)__使用详解》中分析了isLoggable的使用方法,本文主要分析isLoggable实现原理以及user版系统root后永久enable isLoggable的原理,并使用脚本自动设置isLoggable相关属...
  • 在上文《Android 5.0 怎样正确启用isLoggable(一)__使用具体解释》中分析了isLoggable的用法,本文主要分析isLoggable实现原理以及user版系统root后永久enable isLoggable的原理,并使用脚本自己主动...
  • 在Android源码中,经常可以看到使用isLoggable来控制Log输出的代码,该方法可以非常方便的控制log输出,无论在user/userdebug/eng版本的系统中,isLoggable都能正常激活,便于开发者调试。
  • 出现错误The type EncodingFilter must implement the inherited abstract method Filter.isLoggable(LogRecord),是因为导包导错了。删掉import java.util.logging.Filter; 然后按住ctrl+shift+o,快捷键调整导包,...
  • isLoggable是什么 在Android源代码中,我们常常能够看到例如以下代码: //packages/apps/InCallUI/src/com/android/incallui/Log.java public static final String TAG = "InCall"; public static final boolean...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 3,540
精华内容 1,416
关键字:

isLoggable