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

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

问题描述

我想我的应用程序的日志重定向到SD卡文件。但我没有这样做。我想这样的事情。

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<文件名> ,以将其转储到文件系统中的文件。
请确保您使用的文件名是在SD卡,即始于 / SD卡/...

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的完整路径: /系统/斌/ logcat的,而不是仅仅的logcat

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

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