Android Log.isLoggable 妙用

近來發現源碼裏面好多地方用到了 Log.isLoggable , 一查一看,是個東西,適合系統層以及root 主板設備上使用,能實現動態開關
android.util.Log.isLoggable(TAG, android.util.Log.DEBUG)

如上面代碼以及文檔說明,setprop log.tag.YOUR_LOG_TAG LEVEL 開啓指定級別的日誌開關屬性,VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT, or SUPPRESS. SUPPRESS will turn off all logging for your tag. 一目瞭然了啊,

adb shell setprop log.tag.VxApk D
adb shell setprop log.tag.SUPPRESS

另外還有收穫的是,系統重啓之後prop 會被還原,所以瞭解到了重啓系統服務這招,ServiceManager/ SystemServer/

adb shell stop
adb shell start

public static boolean restartSystemServer() {
        try {
            OutputStream out;
            Process process = createSuProcess();
            String cmd = "stop \n";
            out = process.getOutputStream();
            out.write(cmd.getBytes());
            cmd = "start \n";
            out.write(cmd.getBytes());
            out.flush();
            out.close();
            return true;
        } catch (IOException e) {
            Log.error(TAG, "restartSystemServer error");
        }
        return false;
 }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章