Skip to content

Commit

Permalink
more log
Browse files Browse the repository at this point in the history
  • Loading branch information
sunwu51 committed Feb 18, 2024
1 parent e07f17d commit b2a7bc5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 40 deletions.
31 changes: 16 additions & 15 deletions src/main/java/w/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ public static void error(Object content) {
log(2, "" + content);
}

/**
* Print error log, and broadcast to all websocket client
* @param content
* @param e
*/
public static void error(Object content, Throwable e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String stackTraceString = sw.toString();
log(2, content + "\n" + stackTraceString);
}

/**
* To pretty string, by m3.prettyobjct.*
* @param obj
Expand All @@ -174,11 +187,7 @@ public static String toJson(Object obj) throws JsonProcessingException {
try {
return PrintUtils.getObjectMapper().writeValueAsString(obj);
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String stackTraceString = sw.toString();
Global.error("re transform error:\n " + stackTraceString);
Global.error("re transform error:", e);
return "toJson error";
}
}
Expand Down Expand Up @@ -229,11 +238,7 @@ public static synchronized void deleteTransformer(UUID uuid) {
try {
instrumentation.retransformClasses(aClass);
} catch (UnmodifiableClassException e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String stackTraceString = sw.toString();
Global.error("re transform error:\n " + stackTraceString);
Global.error("re transform error:", e);
}
}
return true;
Expand Down Expand Up @@ -275,11 +280,7 @@ public static synchronized void reset() {
try {
instrumentation.retransformClasses(aClass);
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String stackTraceString = sw.toString();
Global.error("reset re transform error:\n " + stackTraceString);
Global.error("reset re transform error: ", e);
}
}

Expand Down
12 changes: 2 additions & 10 deletions src/main/java/w/core/Swapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ public boolean swap(Message message) {
throw new RuntimeException("message type not support");
}
} catch (Throwable e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String stackTraceString = sw.toString();
Global.error("build transform error:\n " + stackTraceString);
Global.error("build transform error:", e);
return false;
}

Expand All @@ -60,11 +56,7 @@ public boolean swap(Message message) {
try {
Global.addActiveTransformer(aClass, transformer);
} catch (Throwable e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String stackTraceString = sw.toString();
Global.error("re transform error:\n " + stackTraceString);
Global.error("re transform error:", e);
return false;
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/w/core/model/BaseClassTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
Global.info(className + " re transform by " + uuid + " success <(^-^)>");
return r;
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String stackTraceString = sw.toString();
Global.error(className + " re transform fail by " + uuid + " -(′д`)-: \n " + stackTraceString);
Global.error(className + " re transform fail by " + uuid + " -(′д`)-: ", e);
}
}
return null;
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/w/web/Websocketd.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ private void dispatch(String msg) {
try {
Global.deleteTransformer(UUID.fromString(deleteMessage.getUuid()));
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String stackTraceString = sw.toString();
Global.error("delete error:\n " + stackTraceString);
Global.error("delete error:", e);
}
}
break;
Expand All @@ -95,11 +91,7 @@ private void dispatch(String msg) {
e.printStackTrace();
Global.error("not a valid message");
} catch (Throwable e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String stackTraceString = sw.toString();
Global.error("error:\n " + stackTraceString);
Global.error("error:", e);
} finally {
RequestUtils.clearRequestCtx();
}
Expand Down

0 comments on commit b2a7bc5

Please sign in to comment.