Is there any way of seeing the full logcat log? I have an error in my app but I don't have time to see it because lots of text appears after the error and goes past the limit of lines in the logcat. So even if I go to the top the error is already gone.
You should use the filter in Android Studio. Here are some options you have:
Add custom TAG to the place where the error is thrown and filter by that:
Log.e(custom_tag, message, throwable);
Also, if you don't want the logcat to be scrolled automatically, just select a piece of output in the middle (or scroll up).
This is another idea to store your logcat detail for testing purpose Try below code
public static void extractLogToFile() {
PackageManager manager = getContext().getPackageManager();
PackageInfo info = null;
try {
info = manager.getPackageInfo(getContext().getPackageName(), 0);
} catch (NameNotFoundException e2) {
}
String model = Build.MODEL;
if (!model.startsWith(Build.MANUFACTURER))
model = Build.MANUFACTURER + " " + model;
String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "your App name" + File.separator;
File folder = new File(filePath);
if (!folder.exists()) {
folder.mkdir();
}
String fileName = "Logcat-" + (new SimpleDateFormat("dd-MM-yyyy").format(Calendar.getInstance().getTime())) + ".txt";
File file = new File(folder, fileName);
InputStreamReader reader = null;
FileWriter writer = null;
try {
// For Android 4.0 and earlier, you will get all app's log output,
// so filter it to
// mostly limit it to your app's output. In later versions, the
// filtering isn't needed.
String cmd = (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) ? "logcat -d -v time MyApp:v dalvikvm:v System.err:v *:s" : "logcat -d -v time";
// get input stream
Process process = Runtime.getRuntime().exec(cmd);
reader = new InputStreamReader(process.getInputStream());
// write output stream
writer = new FileWriter(file, true);
writer.write("Android version: " + Build.VERSION.SDK_INT + "\n");
writer.write("Device: " + model + "\n");
writer.write("App version: " + (info == null ? "(null)" : info.versionCode) + "\n");
char[] buffer = new char[10000];
do {
int n = reader.read(buffer, 0, buffer.length);
if (n == -1)
break;
writer.write(buffer, 0, n);
} while (true);
reader.close();
writer.close();
} catch (IOException e) {
if (writer != null)
try {
writer.close();
} catch (IOException e1) {
}
if (reader != null)
try {
reader.close();
} catch (IOException e1) {
}
}
}
hope this will work
By this code, you can store logcat detail in your phone storage. make sure storage permission mentioned in your manifest file as well as implement runtime permission.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.