File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed
EasyRest/src/main/java/tech/dbgsoftware/easyrest/utils Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -123,16 +123,16 @@ public static void error(String message, Object object){
123123
124124 public static void error (String message , Exception e ){
125125 if (e instanceof PageNotFoundException ) {
126- error (message + "\r \n " + ThreadStackUtils .getStackInfo ());
126+ error (message + "\r \n " + ThreadStackUtils .getStackInfo (e ));
127127 if (ERROR_FUNCTION != null ) {
128128 StringBuilder stringBuilder = new StringBuilder ();
129129 stringBuilder .append ('[' );
130130 stringBuilder .append (Thread .currentThread ().getName ());
131131 stringBuilder .append ("] " );
132- EXECUTOR_SERVICE .execute (() -> ERROR_FUNCTION .apply (stringBuilder .append (message ).append ("\r \n " ).append (ThreadStackUtils .getStackInfo ()).toString ()));
132+ EXECUTOR_SERVICE .execute (() -> ERROR_FUNCTION .apply (stringBuilder .append (message ).append ("\r \n " ).append (ThreadStackUtils .getStackInfo (e )).toString ()));
133133 }
134134 } else {
135- String error = String .format ("%s %s" , String .valueOf (new Date ()), message + "\r \n " + ThreadStackUtils .getStackInfo ());
135+ String error = String .format ("%s %s" , String .valueOf (new Date ()), message + "\r \n " + ThreadStackUtils .getStackInfo (e ));
136136 LOGGER .error (error , e );
137137 if (ERROR_FUNCTION != null ) {
138138 StringBuilder stringBuilder = new StringBuilder ();
Original file line number Diff line number Diff line change @@ -13,8 +13,24 @@ public static String getStackInfo() {
1313 return stringBuffer .toString ();
1414 }
1515
16+ public static String getStackInfo (Exception e ) {
17+ StringBuilder stringBuffer = new StringBuilder ();
18+ for (int i = Math .min (3 , e .getStackTrace ().length ); i < Math .min (18 , e .getStackTrace ().length ); i ++) {
19+ String className = e .getStackTrace ()[i ].getClassName ();
20+ String methodName = e .getStackTrace ()[i ].getMethodName ();
21+ String line = String .valueOf (e .getStackTrace ()[i ].getLineNumber ());
22+ stringBuffer .append (className ).append (":" ).append (methodName ).append (":" ).append (line ).append ("\r \n " );
23+ }
24+ return stringBuffer .toString ();
25+ }
26+
1627 public static void main (String [] args ) {
17- System .out .println (getStackInfo ());
28+ try {
29+ System .out .println (123 );
30+ System .out .println (Double .valueOf ("" ));
31+ } catch (Exception e ) {
32+ System .out .println (JsonTranslationUtil .toJsonString (getStackInfo (e )));
33+ }
1834 }
1935
2036}
You can’t perform that action at this time.
0 commit comments