如何将我的日志输出从 logcat 重定向到 Android 设备上的 SD 卡? [英] How to redirect my log output from logcat to the SD-Card on an android device?

查看:22
本文介绍了如何将我的日志输出从 logcat 重定向到 Android 设备上的 SD 卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的应用程序日志重定向到 sdcard 文件.但我没有这样做.我正在尝试这样的事情.

I'm trying to redirect the log of my app to the sdcard file. But i failed to do so. I'm trying something like this.

String cmd= "logcat -v time   ActivityManager:W  myapp:D  *:* >""+file.getAbsolutePath()+""";
Runtime.getRuntime().exec(cmd);

我也尝试了 -f 选项,但它也不起作用.

I tried the -f option also but it is not working either.

推荐答案

使用 logcat -f 将其转储到文件系统中的文件中.
确保您使用的文件名在 sdcard 中,即以 /sdcard/... 开头.

use logcat -f <filename> in order to dump it to a file in the filesystem.
Make sure the filename you're using is in the sdcard, i.e. starts with /sdcard/....

此外,为了向 logcat 程序传递参数,您应该向 exec 方法传递一个字符串数组(而不是一个字符串):

Also, in order to pass arguments to the logcat program, you should pass the exec method an array of strings (and not one string):

String[] cmd = new String[] { "logcat", "-f", "/sdcard/myfilename", "-v", "time", "ActivityManager:W", "myapp:D" };

最后,如果所有其他方法都失败了,请使用 logcat 的完整路径:/system/bin/logcat 而不是 logcat.

Finally, if all else fails, use the full path for logcat: /system/bin/logcat instead of just logcat.

这篇关于如何将我的日志输出从 logcat 重定向到 Android 设备上的 SD 卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆