How I start a process to run logcat on Android?

Posted by tangjie on Stack Overflow See other posts from Stack Overflow or by tangjie
Published on 2010-12-29T06:48:59Z Indexed on 2010/12/29 6:54 UTC
Read the original article Hit count: 257

Filed under:
|
|

I want to read Android system level log file.So I use the following code:

        Process mLogcatProc = null;
    BufferedReader reader = null;
    try {
        mLogcatProc = Runtime.getRuntime().exec(
                new String[] { "logcat", "-d",
                        "AndroidRuntime:E [Your Log Tag Here]:V *:S" });

        reader = new BufferedReader(new InputStreamReader(mLogcatProc
                .getInputStream()));

        String line;
        final StringBuilder log = new StringBuilder();
        String separator = System.getProperty("line.separator");

        while ((line = reader.readLine()) != null) {
            log.append(line);
            log.append(separator);
        }

    }

    catch (IOException e) {}
    finally {
        if (reader != null)
            try {
                reader.close();
            } catch (IOException e) {}

    }

I also used in AndroidManifest.xml. But I can't read any line. The StringBuilder log is empty. And the method mLogcatProc.waitFor return 0.

So how can I read the log ?

© Stack Overflow or respective owner

Related posts about android

Related posts about log