我正在使用Android的日志来监督应用程序的使用,所以我将logcat放入手机中,而不是在Eclipse中。那么,如果我只是在日志中写入信息并向我发送信息,那么一切都可以,但是我从以前的执行中收到信息。 我决定每次启动应用程序时清除日志,但现在通常会丢失第一条日志消息。也许logcat需要一些时间才能清除?因为当我尝试去调试所有的东西都没关系。清除logcat(Android)的问题
实施例:
清除日志,消息1,消息2,消息3,...
有时候我不接收消息1,有时没有收到1和2 ...
我检查了我所有的代码可能意外清零,但我没有发现任何东西......
我调用此函数开头(中的onCreate())
public static void clearLog(){
ArrayList<String> commandLine = new ArrayList<String>();
commandLine.add("logcat");
commandLine.add("-c");//CLEAR
Runtime process = Runtime.getRuntime();
process.exec(commandLine.toArray(new String[0]));
TAG = "";
}
然后,添加日志
log.i(TAG, "message1");
..
log.i(TAG, "messageN");
而且这是我收集日志:
ArrayList<String> commandLine = new ArrayList<String>();
commandLine.add("logcat");
commandLine.add("-d");//dump and exit
commandLine.add("-v");//especify verbose mode
commandLine.add("raw");//raw show only the message, brief for show all
commandLine.add(TAG + ":V");//show TAG's log
commandLine.add("*:S");//hide others
Process process = Runtime.getRuntime().exec(
commandLine.toArray(new String[0]));
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line, log = "";
while ((line = bufferedReader.readLine()) != null) {
log += line + LINE_SEPARATOR;
}
你把你的“清除日志”代码放在哪里?添加一些代码来完成问题。 –
新增我如何清除它,写下并收集,对不起。 – adalPaRi