/**
* * * log level:*:v , *:d , *:w , *:e , *:f , *:s * * Show the
* current mPID process level of E and W log. * *
*/
// cmds = "logcat *:e *:w | grep \"(" + mPID + ")\"";
cmds = "logcat *:e *:w | grep \"(" + mPID + ")\"";
}
public void stopLogs()
{
mRunning = false;
}
@Override
public void run()
{
try
{
logcatProc = Runtime.getRuntime().exec(cmds);
mReader = new BufferedReader(new InputStreamReader(logcatProc.getInputStream()), 1024);
String line = null;
while (mRunning && (line = mReader.readLine()) != null)
{
if (!mRunning)
{
break;
}
if (line.length() == 0)
{
continue;
}
if (out != null && line.contains(mPID))
{
out.write((simpleDateFormat2.format(new Date()) + " " + line + "\n").getBytes());
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
if (logcatProc != null)
{
logcatProc.destroy();
logcatProc = null;
}
if (mReader != null)
{
try
{
mReader.close();
mReader = null;
}
catch (IOException e)
{
e.printStackTrace();
}
}
if (out != null)
{
try
{
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
out = null;
}
}
}
}
}
然后在应用启动和退出时关闭管理器就行
-------------------------------------------分割线-------------------------------------------