Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,22 @@
import java.io.StringWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Formatter;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -345,7 +351,9 @@ private static String formatObject(Object object) {
if (object instanceof Throwable) return LogFormatter.throwable2String((Throwable) object);
if (object instanceof Bundle) return LogFormatter.bundle2String((Bundle) object);
if (object instanceof Intent) return LogFormatter.intent2String((Intent) object);
return object.toString();
if (object instanceof Map) return LogFormatter.map2String((Map) object);
if (object instanceof Collection) return LogFormatter.collection2String((Collection) object);
return LogFormatter.object2String(object);
}

private static void print2Console(final int type,
Expand Down Expand Up @@ -982,6 +990,58 @@ static String intent2String(Intent intent) {
return sb.toString();
}

static String map2String(Map map) {
JSONObject jsonObject = new JSONObject(map);
return jsonObject.toString();
}

static String collection2String(Collection collection) {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("size", collection.size());
jsonObject.put("data", collection);
return jsonObject.toString();
} catch (JSONException ignore) {
return collection.toString();
}
}

static String object2String(Object object) {
if (object instanceof String || object instanceof JSONObject ||
object instanceof JSONArray) {
return object.toString();
}
Class<?> clazz = object.getClass();
List<Field> tmp = Arrays.asList(clazz.getDeclaredFields());
ArrayList<Field> list = new ArrayList<>(tmp);
while (clazz != Object.class) {
clazz = clazz.getSuperclass();
if (clazz == null) {
break;
}
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
int modifier = field.getModifiers();
if (Modifier.isPublic(modifier)) {
list.add(field);
}
}
}
Field[] a = new Field[list.size()];
Field[] fields = list.toArray(a);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("object", object.toString());
for (Field field : fields) {
String fieldName = field.getName();
Object obj = field.get(object);
jsonObject.put(fieldName, obj);
}
} catch (Exception ignore) {
}
return jsonObject.toString();
}

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
private static void clipData2String(ClipData clipData, StringBuilder sb) {
ClipData.Item item = clipData.getItemAt(0);
Expand Down