Skip to content

Commit

Permalink
Merge pull request #504 from F43nd1r/logcat
Browse files Browse the repository at this point in the history
Simplify logcatcollector
  • Loading branch information
william-ferguson-au authored Sep 5, 2016
2 parents 2e4e020 + 82850f1 commit e573693
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/main/java/org/acra/collector/LogCatCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
import org.acra.ACRA;
import org.acra.annotation.ReportsCrashes;
import org.acra.config.ACRAConfiguration;
import org.acra.collections.BoundedLinkedList;
import org.acra.util.IOUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import static org.acra.ACRA.LOG_TAG;
Expand Down Expand Up @@ -63,10 +61,7 @@ class LogCatCollector {
*/
public String collectLogCat(@NonNull ACRAConfiguration config, @Nullable String bufferName) {
final int myPid = android.os.Process.myPid();
String myPidStr = null;
if (config.logcatFilterByPid() && myPid > 0) {
myPidStr = Integer.toString(myPid) +"):";
}
final String myPidStr = config.logcatFilterByPid() && myPid > 0 ? Integer.toString(myPid) + "):" : null;

final List<String> commandLine = new ArrayList<String>();
commandLine.add("logcat");
Expand All @@ -92,8 +87,7 @@ public String collectLogCat(@NonNull ACRAConfiguration config, @Nullable String
tailCount = -1;
}

final LinkedList<String> logcatBuf = new BoundedLinkedList<String>(tailCount > 0 ? tailCount
: DEFAULT_TAIL_COUNT);
String logcat = "N/A";
commandLine.addAll(logcatArgumentsList);

try {
Expand All @@ -112,18 +106,17 @@ public void run() {
}
}).start();

final String finalMyPidStr = myPidStr;
logcatBuf.add(IOUtils.streamToString(process.getInputStream(), new Predicate<String>() {
logcat = IOUtils.streamToString(process.getInputStream(), new Predicate<String>() {
@Override
public boolean apply(String s) {
return finalMyPidStr == null || s.contains(finalMyPidStr);
return myPidStr == null || s.contains(myPidStr);
}
}));
}, tailCount > 0 ? tailCount : DEFAULT_TAIL_COUNT);

} catch (IOException e) {
ACRA.log.e(LOG_TAG, "LogCatCollector.collectLogCat could not retrieve data.", e);
}

return logcatBuf.toString();
return logcat;
}
}

0 comments on commit e573693

Please # to comment.