Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify logcatcollector #504

Merged
merged 1 commit into from
Sep 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}