Skip to content

Instantly share code, notes, and snippets.

@orip
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orip/2957730757e9246c3cfd to your computer and use it in GitHub Desktop.
Save orip/2957730757e9246c3cfd to your computer and use it in GitHub Desktop.
import com.google.common.io.CharStreams;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Zero error checking or recovery. Apologies.
*
* Requires the READ_LOGS permission.
*/
public class ReadingLogcat {
public static String getLogcatOutputWithGuava() throws IOException {
Process logcat = Runtime.getRuntime().exec("logcat -d");
return CharStreams.toString(new InputStreamReader(logcat.getInputStream()));
}
public static String getLogcatOutputNoGuava() throws IOException {
Process logcat = Runtime.getRuntime().exec("logcat -d");
BufferedReader reader = new BufferedReader(new InputStreamReader(logcat.getInputStream()));
StringBuilder result = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
}
return result.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment