Skip to content

Commit e6d5de4

Browse files
committed
Add log details.
1 parent 76bbbcc commit e6d5de4

File tree

1 file changed

+45
-9
lines changed
  • EasyRest/src/main/java/tech/dbgsoftware/easyrest/utils

1 file changed

+45
-9
lines changed

EasyRest/src/main/java/tech/dbgsoftware/easyrest/utils/LogUtils.java

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,53 +42,81 @@ public static void info(String string, Class aClass){
4242
String log = String.format("%s %s", String.valueOf(new Date()), "From " + aClass.getName() + ": " + string);
4343
LOGGER.info(log);
4444
if (INFO_FUNCTION != null) {
45-
EXECUTOR_SERVICE.execute(() -> INFO_FUNCTION.apply(log));
45+
StringBuilder stringBuilder = new StringBuilder();
46+
stringBuilder.append('[');
47+
stringBuilder.append(Thread.currentThread().getName());
48+
stringBuilder.append("] ");
49+
EXECUTOR_SERVICE.execute(() -> INFO_FUNCTION.apply(stringBuilder.append(log).toString()));
4650
}
4751
}
4852

4953
public static void info(Object obj, Class aClass){
5054
String log = String.format("%s %s", String.valueOf(new Date()), "From " + aClass.getName() + ": " + GSON.toJson(obj));
5155
LOGGER.info(log);
5256
if (INFO_FUNCTION != null) {
53-
EXECUTOR_SERVICE.execute(() -> INFO_FUNCTION.apply(log));
57+
StringBuilder stringBuilder = new StringBuilder();
58+
stringBuilder.append('[');
59+
stringBuilder.append(Thread.currentThread().getName());
60+
stringBuilder.append("] ");
61+
EXECUTOR_SERVICE.execute(() -> INFO_FUNCTION.apply(stringBuilder.append(log).toString()));
5462
}
5563
}
5664

5765
public static void info(String string){
5866
String log = String.format("%s %s", String.valueOf(new Date()), string);
5967
LOGGER.info(log);
6068
if (INFO_FUNCTION != null) {
61-
EXECUTOR_SERVICE.execute(() -> INFO_FUNCTION.apply(log));
69+
StringBuilder stringBuilder = new StringBuilder();
70+
stringBuilder.append('[');
71+
stringBuilder.append(Thread.currentThread().getName());
72+
stringBuilder.append("] ");
73+
EXECUTOR_SERVICE.execute(() -> INFO_FUNCTION.apply(stringBuilder.append(log).toString()));
6274
}
6375
}
6476

6577
public static void info(Object obj){
6678
String log = String.format("%s %s", String.valueOf(new Date()), GSON.toJson(obj));
6779
LOGGER.info(log);
6880
if (INFO_FUNCTION != null) {
69-
EXECUTOR_SERVICE.execute(() -> INFO_FUNCTION.apply(log));
81+
StringBuilder stringBuilder = new StringBuilder();
82+
stringBuilder.append('[');
83+
stringBuilder.append(Thread.currentThread().getName());
84+
stringBuilder.append("] ");
85+
EXECUTOR_SERVICE.execute(() -> INFO_FUNCTION.apply(stringBuilder.append(log).toString()));
7086
}
7187
}
7288

7389
public static void error(String message){
7490
String error = String.format("%s %s", String.valueOf(new Date()), message + "\r\n" + ThreadStackUtils.getStackInfo());
7591
LOGGER.error(error);
7692
if (ERROR_FUNCTION != null) {
77-
EXECUTOR_SERVICE.execute(() -> ERROR_FUNCTION.apply(error));
93+
StringBuilder stringBuilder = new StringBuilder();
94+
stringBuilder.append('[');
95+
stringBuilder.append(Thread.currentThread().getName());
96+
stringBuilder.append("] ");
97+
EXECUTOR_SERVICE.execute(() -> ERROR_FUNCTION.apply(stringBuilder.append(error).toString()));
7898
}
7999
}
80100

81101
public static void error(String message, Object object){
82102
if (object == null) {
83103
error(message + "\r\n" + ThreadStackUtils.getStackInfo());
84104
if (ERROR_FUNCTION != null) {
85-
EXECUTOR_SERVICE.execute(() -> ERROR_FUNCTION.apply(message + "\r\n" + ThreadStackUtils.getStackInfo()));
105+
StringBuilder stringBuilder = new StringBuilder();
106+
stringBuilder.append('[');
107+
stringBuilder.append(Thread.currentThread().getName());
108+
stringBuilder.append("] ");
109+
EXECUTOR_SERVICE.execute(() -> ERROR_FUNCTION.apply(stringBuilder.append(message).append("\r\n").append(ThreadStackUtils.getStackInfo()).toString()));
86110
}
87111
} else {
88112
String error = String.format("%s %s", String.valueOf(new Date()), message + "\r\n" + ThreadStackUtils.getStackInfo());
89113
LOGGER.error(error, object);
90114
if (ERROR_FUNCTION != null) {
91-
EXECUTOR_SERVICE.execute(() -> ERROR_FUNCTION.apply(error));
115+
StringBuilder stringBuilder = new StringBuilder();
116+
stringBuilder.append('[');
117+
stringBuilder.append(Thread.currentThread().getName());
118+
stringBuilder.append("] ");
119+
EXECUTOR_SERVICE.execute(() -> ERROR_FUNCTION.apply(stringBuilder.append(error).toString()));
92120
}
93121
}
94122
}
@@ -97,13 +125,21 @@ public static void error(String message, Exception e){
97125
if (e instanceof PageNotFoundException) {
98126
error(message + "\r\n" + ThreadStackUtils.getStackInfo());
99127
if (ERROR_FUNCTION != null) {
100-
EXECUTOR_SERVICE.execute(() -> ERROR_FUNCTION.apply(message + "\r\n" + ThreadStackUtils.getStackInfo()));
128+
StringBuilder stringBuilder = new StringBuilder();
129+
stringBuilder.append('[');
130+
stringBuilder.append(Thread.currentThread().getName());
131+
stringBuilder.append("] ");
132+
EXECUTOR_SERVICE.execute(() -> ERROR_FUNCTION.apply(stringBuilder.append(message).append("\r\n").append(ThreadStackUtils.getStackInfo()).toString()));
101133
}
102134
} else {
103135
String error = String.format("%s %s", String.valueOf(new Date()), message + "\r\n" + ThreadStackUtils.getStackInfo());
104136
LOGGER.error(error, e);
105137
if (ERROR_FUNCTION != null) {
106-
EXECUTOR_SERVICE.execute(() -> ERROR_FUNCTION.apply(error));
138+
StringBuilder stringBuilder = new StringBuilder();
139+
stringBuilder.append('[');
140+
stringBuilder.append(Thread.currentThread().getName());
141+
stringBuilder.append("] ");
142+
EXECUTOR_SERVICE.execute(() -> ERROR_FUNCTION.apply(stringBuilder.append(message).toString()));
107143
}
108144
}
109145
}

0 commit comments

Comments
 (0)