Android isLoggable返回不稳定的结果?

时间:2016-08-04 02:26:21

标签: android logging

我有一个自定义同步适配器类,并且在它的onPerformSync()方法中,我正在尝试编写几个调试日志消息,而我正在使用Android的isLoggable()和setprop log.tag.SB_ArchiveOrgSyncAdapte DEBUG一起使用我的测试设备。我使用相同的方法在适配器的OnPerformSync()方法中的各个点写出每个日志消息,但通常isLoggable()返回false。下面是我的logcat示例,其中我添加了一些错误日志记录,以显示当isLoggable()失败时,通过调试日志尝试记录的内容。

E/LogHelper: TAG Not Loggable: SB_ArchiveOrgSyncAdapte, Level: 3, msg: ====== PERFORMING SYNC ======
E/LogHelper: TAG Not Loggable: SB_ArchiveOrgSyncAdapte, Level: 3, msg: Inserted a set of data: 2379 rows
E/LogHelper: TAG Not Loggable: SB_ArchiveOrgSyncAdapte, Level: 3, msg: Inserted a set of data: 2292 rows
E/LogHelper: TAG Not Loggable: SB_ArchiveOrgSyncAdapte, Level: 3, msg: Inserted a set of data: 2241 rows
D/SB_ArchiveOrgSyncAdapte: ====== TEST LOG MESSAGE ======
E/LogHelper: TAG Not Loggable: SB_ArchiveOrgSyncAdapte, Level: 3, msg: Inserted a set of data: 2382 rows
D/SB_ArchiveOrgSyncAdapte: Inserted a set of data: 2503 rows
E/LogHelper: TAG Not Loggable: SB_ArchiveOrgSyncAdapte, Level: 3, msg: Inserted a set of data: 785 rows
E/LogHelper: TAG Not Loggable: SB_ArchiveOrgSyncAdapte, Level: 3, msg: ====== SYNC POST-EXECUTE COMPLETE ======

所有上述消息都是在我的OnPerformSync()方法中使用相同的记录方法调用输出的:

public void debug(String TAG, String message) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.println(Log.DEBUG, TAG, message);
    } else {
        Log.e("LogHelper", "Not Loggable: " + TAG + ", Level: " + Log.DEBUG + ", msg: " + message);
    }
}

那么为什么一些isLoggable()调用返回false,而其他调用返回true?对TAG

的所有调用中debug()都是相同的(SB_ArchiveOrgSyncAdapte)

0 个答案:

没有答案