I am trying to display long message on logcat. If the length of message is more than 1000 characters, it gets broken.
What is the mechanism to show all characters o
Here is a Kotlin version for the @spatulamania answer (especially for lazy/smart peooples):
val maxLogSize = 1000
val stringLength = yourString.length
for (i in 0..stringLength / maxLogSize) {
val start = i * maxLogSize
var end = (i + 1) * maxLogSize
end = if (end > yourString.length) yourString.length else end
Log.v("YOURTAG", yourString.substring(start, end))
}
For an easy solution, use Use soft wrap option in below attach point no 4 options might help you.
In order not to minimize splitting lines across log messages, I take the large string and log each line separately.
void logMultilineString(String data) {
for (String line : data.split("\n")) {
logLargeString(line);
}
}
void logLargeString(String data) {
final int CHUNK_SIZE = 4076; // Typical max logcat payload.
int offset = 0;
while (offset + CHUNK_SIZE <= data.length()) {
Log.d(TAG, data.substring(offset, offset += CHUNK_SIZE));
}
if (offset < data.length()) {
Log.d(TAG, data.substring(offset));
}
}
If logcat is capping the length at 1000 then you can split the string you want to log with String.subString() and log it in pieces. For example:
int maxLogSize = 1000;
for(int i = 0; i <= veryLongString.length() / maxLogSize; i++) {
int start = i * maxLogSize;
int end = (i+1) * maxLogSize;
end = end > veryLongString.length() ? veryLongString.length() : end;
Log.v(TAG, veryLongString.substring(start, end));
}