For default Log on android platform has limited amount of character for console output. Around equal a bit more than 3000. Therefore, if the message is longer than 3000 characters, it is not shown on screen.
I have not found a better solution than this:
public class Log {
private static int mode = android.util.Log.INFO;
public static void e(String tag, String msg, Throwable tr) {
if ((mode & android.util.Log.ERROR) <= 0) return;
android.util.Log.e(tag, msg, tr);
}
public static void e(String tag, String msg) {
if ((mode & android.util.Log.ERROR) <= 0) return;
android.util.Log.e(tag, msg);
}
public static void w(String tag, String msg) {
if ((mode & android.util.Log.WARN) <= 0) return;
android.util.Log.w(tag, msg);
}
public static void i(String tag, String msg) {
if ((mode & android.util.Log.INFO) <= 0) return;
android.util.Log.i(tag, msg);
}
public static void d(String tag, String msg) {
if ((mode & android.util.Log.DEBUG) <= 0) return;
int length = msg.length();
int kind = 3000;
if (length >= kind) {
int count = length / kind;
int u = length % kind;
int i = 0;
for (i = 0; i < count; ++i) {
int start = i * kind;
int end = start + kind;
android.util.Log.d(tag, msg.substring(start, end));
}
if (u != 0) {
int start = length - u;
int end = start + u;
android.util.Log.d(tag, msg.substring(start, end));
}
} else {
android.util.Log.d(tag, msg);
}
}
}
Is there a better solution to this issue?
in the upper menu of Android Studio. In the bottom status bar, click 5: Debug button, next to the 4: Run button. Now you should select the Logcat console. Check this article for more information.
A workaround for the 1024 character limit when doing large outputs (JSON etc) is to make a simple for-loop, logging them in chunks.
It may not be as elaborate as yours, but it's easy on the eyes and won't clutter the code too much.
String json = data.toString();
int length = json.length();
for(int i=0; i<length; i+=1024)
{
if(i+1024<length)
Log.d("JSON OUTPUT", json.substring(i, i+1024));
else
Log.d("JSON OUTPUT", json.substring(i, length));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With