[英]How to save android runtime error logs in device without connected to PC?
I just wanna to ask if it is possible to save android runtime error information in sdcard without device connected to PC?我只是想问一下是否可以在没有设备连接到PC的情况下将android运行时错误信息保存在sdcard中? 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.这是当我拔出 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.从一开始,我虽然这个命令 'adb shell "logcat -v threadtime -f /mnt/sdcard/logcat_log.txt"' 将继续将日志输出到文件 'logcat_log.txt' 中。 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 .经过多次测试、检查和阅读有关 logcat 的文档,我发现此命令只会刷新 android 的日志缓冲区,然后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.感谢 Pragna 和 Narkha 的回复。
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;我的测试平台是windows 7,如果你使用Linux或Mac OS X会更好,解决方案包含windows的bat脚本,android shell的shell脚本; they are run.bat, logcat.sh, run_monkey.sh and run_logcat.sh.它们是 run.bat、logcat.sh、run_monkey.sh 和 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 &"
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.