ResponseLog.java
980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.huaheng.mobilewms.https;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;
public class ResponseLog {
public static int maxSize = 50;
public static List<String> responseList = new ArrayList<>();
public static void add(ApiResponse apiResponse){
try {
if(responseList.size() >= maxSize){
responseList.remove(responseList.size() - 1);
}
String responseBody = new Gson().toJson(apiResponse);
responseList.add(0, responseBody);
}catch (Exception e){
}
}
public static void addException(String err){
try{
if(responseList.size() == 0){
return;
}
// int target = responseList.size() - 1;
int target = 0;
String msg = responseList.get(target) + "\n" + err;
responseList.set(target, msg);
}catch (Exception e){
}
}
}