When registering my tags always look like this:
com.myapp.SomeActivity
For each log statement, I add the first part of "com.myapp". to the class tag that makes the log call. For instance:
MyActivity extends Activity{ private static final String TAG = "MyActivity"; public void someMethod(){ LogWrapper.e(TAG, "Something is wrong here."); } }
My LogWrapper class basically does the following
public class LogWrapper { private static final String applicationTAG = "com.myapp."; public static void e(String classTag, String message){ Log.e(applicationTAG + classTag, message); } }
So, all I do is add a static tag to the class tag. The reason is because I want to filter the output of logcat with the log operations that my application writes, and to avoid cluttering my log file with logs from the system or other applications.
Therefore, I came up with getting the logs as follows:
String command = "logcat -d -v time com.myapp.*:I *:S" Process process = Runtime.getRuntime().exec(command); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream())); StringBuilder log = new StringBuilder(); String line; while ((line = bufferedReader.readLine()) != null) { log.append(line); log.append(StringUtils.NEW_LINE); }
However, in the end I get an empty log file. Which makes me the subject of the regular expression "com.myapp.:I" does not work. I also tried to exclude asterix (), but this does not work. However, if I use "*: I", that works.
Which makes me wonder if it is only possible to filter by the full name of the tag? Is there a way that I can get the log filtered by "com.myapp".
I assume that plan B will be that in a while loop I could check if the string contains my tag and only add it if it is, but I really would like to avoid it ..