Reputation: 155
We have a situation here where we want to see some logging when our IONIC1 app crashes (even if it keeps crashing). We thought about reading the logcat, but this only works if you have a rooted device.... It works then, but since we can't have all the devices here with us to manually run the adb script to grant root log to a logging app, I don't know what to do. Anyone who had the same situation, and came with a solution?
Thanks in advance!
Upvotes: 1
Views: 1215
Reputation: 500
you should try some 3rd party logging tools, would recommend you start with Fabric! (Specifically for Crashlytics)
UPDATE:
If you want to write your logcats to a file, try something along these lines:
try {
Process process = Runtime.getRuntime().exec("logcat -d ");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
log.append(line).append("\n");
}
} catch (IOException ignored) {
}
String address = writeToLogcatFile(c, log.toString());
boolean success = !address.equals("");
Also consider creating your own logger and just adding the ability to export it, just make a bunch of functions that calls your logging as appropriate
public static void v(String TAG, String msg) {
Logv(TAG, msg);
if(showOnScreen) {
Galgo.log(TAG + ": V: " + msg);
}
}
private static void Logv(String tag, String msg) {
if(BuildConfig.DEBUG){
log.v(tag, msg);
} else {
logToTheFileToExportOrDBOrSomethingElse();
}
}
Upvotes: 1