How to save android runtime error logs in device without connected to PC?

ⅰ亾dé卋堺 提交于 2020-01-02 19:10:11

问题


I just wanna to ask if it is possible to save android runtime error information in sdcard without device connected to PC? I tried to run:
adb shell "logcat -v threadtime *:V > /mnt/sdcard/logcat_log.txt"

which is lack of runtime error when I plug out the USB.

Any thoughts? Thanks for your comments.


Here some information I just digged. From the very beginning, I though this command 'adb shell "logcat -v threadtime -f /mnt/sdcard/logcat_log.txt"' will output logs into the file 'logcat_log.txt' continuelly. After several times of testing, checking and document reading about logcat, I have found that this command will only flush log buffers of android and then STOP. That's why I can not get the runtime error info in this file without flush the log buffer again. Thanks Pragna and Narkha for your replys.


I just put my solution here to whom in the future may needs it. My testing platform is windows 7, it would be better if you were using Linux or Mac OS X, and solution contains bat script for windows, shell scripts for android shell; they are run.bat, logcat.sh, run_monkey.sh and run_logcat.sh.

#"run.bat"
adb shell "echo "" > /mnt/sdcard/logcat_log.txt"  #clean up previous log
adb push logcat.sh /mnt/sdcard/            #
start bash run_logcat.sh
start bash run_monkey.sh
pause

#"logcat.sh"
logcat -v threadtime *:V > /mnt/sdcard/logcat_log.txt

#"run_monkey.sh"
adb shell "monkey -p com.test.androidclient --throttle 300 -c android.intent.category.MONKEY -c android.intent.category.LAUNCHER -c android.intent.category.DEFAULT --pct-majornav 20 --monitor-native-crashes --ignore-security-exceptions --ignore-crashes --ignore-timeouts --kill-process-after-error -s 220 -v -v -v 99999" 

#"run_logcat.sh"
adb shell "sh /mnt/sdcard/logcat.sh &"

回答1:


try {
    File logfile= new File(Environment.getExternalStorageDirectory()+"/logfile.log"); 
    filename.createNewFile(); 
    String cmd = "logcat -d -f "+logfile.getAbsolutePath();
    Runtime.getRuntime().exec(cmd);
} catch (IOException e) {

    e.printStackTrace();
}


来源:https://stackoverflow.com/questions/22633217/how-to-save-android-runtime-error-logs-in-device-without-connected-to-pc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!