I am currently working on an android App that uses \'JSON\' as response from server. Usually I work on the JSON response. But now I have a problem with logcat, if the JSON
why not use logcat from a command line?
I doubt whether it will be what you're expecting, but why not give it a try?
issue the command
./adb -e logcat
from the directory which has adb.
this is for emulator.
replace -e
with -d
for a device
if(xml.length() > 4000) {
for(int i=0;i<xml.length();i+=4000){
if(i+4000<xml.length())
Log.i("rescounter"+i,xml.substring(i, i+4000));
else
Log.i("rescounter"+i,xml.substring(i, xml.length()));
}
} else
Log.i("resinfo",xml);
This is how I did it.
In general if you want to get output into Logcat you should use the "Log" command.
An example:
Log.d(TAG,"OUTPUT"):
d = debug
TAG = a string you define, gets displayed in Logcat in the column before the "normal" output
OUTPUT = stuff u want to get printed
Log is a logging class you can use to print out messages to the logcat. You can read messages in real time if you run logcat on DDMS (covered next). Common logging methods include: v(String, String) (verbose), d(String, String) (debug), i(String, String) (information), w(String, String) (warning) and e(String, String) (error).
For further information:
http://developer.android.com/guide/developing/debug-tasks.html
EDIT:
What I ment before is, in order to test some things with outputs you shouldn't use:
System.out.println("JSON stuff");
Instead of using this you should use in your code:
// Values just as example
private static void string TAG = "+++JSON+++";
...
Log.d(TAG,"JSON stuff in here");
...
It will get displayed in Logcat. I don't exactly know why, but it't the better way. Like this you also could display an error message:
Log.e(...);
It will change the color of your output in Logcat, so you may see it better if e.g. an error occurrs.
if you are not using eclipse, or you are but @Nanne answer doesn't work for you I can only think in two alternatives:
edit: Another possibility: write the JSON to a file in SD card like a log, and then retrieve the file when you want to check the response
Some of our RESTful APIs return very long JSON responses. Here's the method which formats them for LogCat:
private static final int LOGCAT_MAX_LENGTH = 3950;
...
private void logLongJsonStringIfDebuggable(String s) {
if (BuildConfig.DEBUG) {
while (s.length() > LOGCAT_MAX_LENGTH) {
int substringIndex = s.lastIndexOf(",", LOGCAT_MAX_LENGTH);
if (substringIndex == -1)
substringIndex = LOGCAT_MAX_LENGTH;
Log.d(TAG, s.substring(0, substringIndex));
s = s.substring(substringIndex).trim();
}
Log.d(TAG, s);
}
}
Ugly but it does the job:
public static void longInfo(String str) {
if(str.length() > 4000) {
Log.i(TAG, str.substring(0, 4000));
longInfo(str.substring(4000));
} else
Log.i(TAG, str);
}