0

I want to create an arraylist of logcat data as follows: time level tag text ..... Example :

06-13 13:34:43:434 W myApp blehblehbleh

How do I filter the logcat to obtain this result? More precisely, what goes into the .exec(" ") part to get these values because "logcat -d" seems to get everything.

    log = new ArrayList<String>();
    try {
        process = Runtime.getRuntime().exec("logcat -d");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    try {

        while ((line = bufferedReader.readLine()) != null){
            log.add(line);

     }
ono
  • 2,984
  • 9
  • 43
  • 85
  • See http://stackoverflow.com/questions/6854127/filter-logcat-to-get-only-the-messages-from-my-application-in-android - it demonstrates the parameters you can pass to logcat. – Michael Banzon Jun 13 '13 at 18:55
  • Yes I would assume "logcat -v tag" would retrieve me the tags but that doesn't work – ono Jun 13 '13 at 19:03
  • See [link](http://stackoverflow.com/questions/9294820/applying-logcat-filter-programmatically) . I tried the answer given there. You can filter out tags only of your app from `logcat -d` – Shruti Dasgopal Nov 27 '15 at 06:54

2 Answers2

2

This will print all the logs from YOUR_TAG_HERE and it will filter out the rest:

logcat -d YOUR_TAG_HERE:V *:S
thiagolr
  • 6,909
  • 6
  • 44
  • 64
  • ./adb logcat -d -v threadtime works to get everything. How do I put this in the .exec() function – ono Jun 13 '13 at 19:57
0

You could simple to do a

if (line.contains("myApp")) log.add(line);

in your loop to only add lines from your app. In your current setup that seems like the quickest way.

Michael Banzon
  • 4,879
  • 1
  • 26
  • 28
  • ./adb logcat -d -v threadtime gets me everything I need. I just need to figure out the syntax for putting it in .exec() – ono Jun 13 '13 at 19:56