Patch to only show own log entries in logcat output

20 views
Skip to first unread message

Kevin Read

unread,
Jan 5, 2012, 5:12:44 AM1/5/12
to acra-d...@googlegroups.com
Hi all,

I have patched the LogCat collector to only include logcat entries that were created by my own PID. This is a hack, the matching should be for the string "PID):", and not only for the number, but I just wanted to get this out there before it sinks back into my pile of code :)

You will probably get less lines of logcat output than you requested, I request 400 lines and get about 200 - but only lines concerning my app. This alleviates privacy issues and requires less bandwidth/space.

Hope this helps. Thanks again for this excellent library.

All the best,

Kevin

Index: acra/collector/LogCatCollector.java
===================================================================
--- acra/collector/LogCatCollector.java (revision 772)
+++ acra/collector/LogCatCollector.java (working copy)
@@ -58,6 +58,11 @@
      *         plan consumption.
      */
     public static String collectLogCat(String bufferName) {
+     final int myPid = android.os.Process.myPid();
+     String myPidStr = null;
+     if (myPid > 0) {
+     myPidStr = Integer.toString(myPid);
+     }
 
         final List<String> commandLine = new ArrayList<String>();
         commandLine.add("logcat");
@@ -96,7 +101,9 @@
                 if (line == null) {
                     break;
                 }
-                logcatBuf.add(line + "\n");
+                if (myPidStr == null || line.contains(myPidStr)) {
+                 logcatBuf.add(line + "\n");
+                }
             }
 
         } catch (IOException e) {

Kevin Gaudin

unread,
Jan 5, 2012, 5:19:56 AM1/5/12
to acra-d...@googlegroups.com
Hi Kevin,

I think I'll add the feature in the next version. Thanks !

Kevin
Reply all
Reply to author
Forward
0 new messages