Skip to content

Commit c5e7265

Browse files
authored
Merge pull request Tencent#238 from cs304-spring2021/master
优化 Debug 日志输出
2 parents 4116e5e + 204ffe5 commit c5e7265

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

APIJSONORM/src/main/java/apijson/Log.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ public static void d(String TAG, String msg) {
2222
}
2323
}
2424

25+
/**
26+
* Forced debug
27+
* @param TAG tag
28+
* @param msg debug messages
29+
*/
30+
public static void fd(String TAG, String msg) {
31+
System.err.println(TAG + ".DEBUG: " + msg);
32+
}
33+
34+
/**
35+
* Generate separation line
36+
* @param pre prefix
37+
* @param symbol used for generating separation line
38+
* @param post postfix
39+
*/
40+
public static void sl(String pre,char symbol ,String post) {
41+
System.err.println(pre+new String(new char[48]).replace('\u0000', symbol)+post);
42+
}
43+
2544
/**
2645
* @param TAG
2746
* @param msg

APIJSONORM/src/main/java/apijson/orm/AbstractParser.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,25 @@
4848
public abstract class AbstractParser<T> implements Parser<T>, ParserCreator<T>, VerifierCreator<T>, SQLCreator {
4949
protected static final String TAG = "AbstractParser";
5050

51+
/**
52+
* 可以通过切换该变量来控制是否打印关键的接口请求内容。保守起见,该值默认为false。
53+
* 与 {@link Log#DEBUG} 任何一个为 true 都会打印关键的接口请求内容。
54+
*/
55+
public static boolean IS_PRINT_REQUEST_STRING_LOG = false;
56+
5157
/**
5258
* 打印大数据量日志的标识。线上环境比较敏感,可以通过切换该变量来控制异常栈抛出、错误日志打印。保守起见,该值默认为false。
5359
* 与 {@link Log#DEBUG} 任何一个为 true 都会打印关键的接口请求及响应信息。
5460
*/
5561
public static boolean IS_PRINT_BIG_LOG = false;
5662

63+
/**
64+
* 可以通过切换该变量来控制是否打印关键的接口请求结束时间。保守起见,该值默认为false。
65+
* 与 {@link Log#DEBUG} 任何一个为 true 都会打印关键的接口请求结束时间。
66+
*/
67+
public static boolean IS_PRINT_REQUEST_ENDTIME_LOG = false;
68+
69+
5770
/**
5871
* method = null
5972
*/
@@ -400,16 +413,18 @@ public JSONObject parseResponse(JSONObject request) {
400413

401414
onClose();
402415

403-
System.err.println("\n\n\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n "
404-
+ TAG + ".DEBUG: " + requestMethod + "/parseResponse request = \n" + requestString + "\n\n");
405-
406-
if (Log.DEBUG || IS_PRINT_BIG_LOG || error != null) { // 日志仅存服务器,所以不太敏感,而且这些日志虽然量大但非常重要,对排查 bug 很关键
407-
System.err.println(TAG + ".DEBUG: " + requestMethod + "/parseResponse return response = \n" + JSON.toJSONString(requestObject) + "\n\n");
416+
//CS304 Issue link: https://github.com/Tencent/APIJSON/issues/232
417+
if (IS_PRINT_REQUEST_STRING_LOG||Log.DEBUG||error != null) {
418+
Log.sl("\n\n\n",'<',"");
419+
Log.fd(TAG , requestMethod + "/parseResponse request = \n" + requestString + "\n\n");
420+
}
421+
if (IS_PRINT_BIG_LOG||Log.DEBUG||error != null) { // 日志仅存服务器,所以不太敏感,而且这些日志虽然量大但非常重要,对排查 bug 很关键
422+
Log.fd(TAG,requestMethod + "/parseResponse return response = \n" + JSON.toJSONString(requestObject) + "\n\n");
423+
}
424+
if (IS_PRINT_REQUEST_ENDTIME_LOG||Log.DEBUG||error != null) {
425+
Log.fd(TAG , requestMethod + "/parseResponse endTime = " + endTime + "; duration = " + duration);
426+
Log.sl("",'>',"\n\n\n");
408427
}
409-
410-
System.err.println(TAG + ".DEBUG: " + requestMethod + "/parseResponse endTime = " + endTime + "; duration = " + duration
411-
+ "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> \n\n\n");
412-
413428
return res;
414429
}
415430

0 commit comments

Comments
 (0)