Selaa lähdekoodia

更新打印异常

wuweihao 3 vuotta sitten
vanhempi
commit
6b336b48b7

+ 10 - 12
720yun_local_consumer/src/main/java/com/gis/listener/Local720Listener.java

@@ -99,26 +99,17 @@ public class Local720Listener {
             // 上传切图
             log.info("任务成功返回: " + obj);
         } catch (InterruptedException e) {
-            e.printStackTrace();
             entity.setStatus(2);
-            StringWriter trace=new StringWriter();
-            log.error(trace.toString());
             log.error("异常了 InterruptedException");
+            printErrorMsg(e);
         } catch (ExecutionException e) {
-            e.printStackTrace();
-            StringWriter trace=new StringWriter();
-            e.printStackTrace(new PrintWriter(trace));
             log.error("超时了 1");
-            // 异常日志要打印,不然不会出现在日志文件中,只会出现在控制台
-            log.error(trace.toString());
             entity.setStatus(2);
+            printErrorMsg(e);
             future.cancel(true);
         } catch (TimeoutException e) {
-            e.printStackTrace();
-            StringWriter trace=new StringWriter();
-            e.printStackTrace(new PrintWriter(trace));
             log.error("超时了 2");
-            log.error(trace.toString());
+            printErrorMsg(e);
             entity.setStatus(2);
             future.cancel(true);
         } finally {
@@ -128,6 +119,13 @@ public class Local720Listener {
         }
     }
 
+    private void printErrorMsg(Exception e){
+        StringWriter trace=new StringWriter();
+        e.printStackTrace(new PrintWriter(trace));
+        log.error(trace.toString());
+    }
+
+
 
 
     /**

+ 15 - 2
720yun_local_manage/gis_admin/src/main/java/com/gis/admin/controller/ExceptionController.java

@@ -17,6 +17,8 @@ import org.springframework.web.servlet.NoHandlerFoundException;
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.ConstraintViolationException;
 import javax.validation.ValidationException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 
 /**
  * 统一捕捉异常,自定义返回参数
@@ -30,7 +32,6 @@ public class ExceptionController {
     @ResponseStatus(HttpStatus.UNAUTHORIZED)
     @ExceptionHandler(ShiroException.class)
     public Result handle401(ShiroException e) {
-//        return Result.failure(5001, e.getMessage());
         log.error("没有授权1");
         return Result.failure(5001, "没有授权");
     }
@@ -71,7 +72,7 @@ public class ExceptionController {
     @ResponseStatus(HttpStatus.OK)
     public Result runtimeExceptionHandler(HttpServletRequest request, BaseRuntimeException e) {
         log.error(request.getRequestURI() + ":" + e.getMsg());
-        e.printStackTrace();
+        printErrorMsg(e);
         return Result.failure(e.getCode(), e.getMsg());
     }
 
@@ -124,6 +125,18 @@ public class ExceptionController {
     }
 
 
+    /**
+     * by owen 2022-4-1
+     * 打印错误详情
+     * @param e
+     */
+    private void printErrorMsg(BaseRuntimeException e){
+        StringWriter trace=new StringWriter();
+        e.printStackTrace(new PrintWriter(trace));
+        log.error(trace);
+    }
+
+
 
 }
 

+ 2 - 20
720yun_local_manage/gis_common/src/main/java/com/gis/common/util/CmdUtils.java

@@ -17,9 +17,9 @@ public class CmdUtils {
         log.info("cmd: {}", command);
         try {
             Process process = Runtime.getRuntime().exec(command);
-            StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR");
+            StreamGobblerLine errorGobbler = new StreamGobblerLine(process.getErrorStream(), "ERROR");
             errorGobbler.start();
-            StreamGobbler outGobbler = new StreamGobbler(process.getInputStream(), "STDOUT");
+            StreamGobblerLine outGobbler = new StreamGobblerLine(process.getInputStream(), "STDOUT");
             outGobbler.start();
             process.waitFor();
         } catch (Exception e) {
@@ -27,24 +27,6 @@ public class CmdUtils {
         }
     }
 
-    /**
-     * 调用算法 xx.sh 脚本
-     * @param command
-     */
-//    public static void callSh(String command, Integer lineSize){
-//        log.info("cmd: {}", command);
-//        try {
-//            String[] cmd = new String[]{"/bin/sh", "-c", command};
-//            Process process = Runtime.getRuntime().exec(cmd);
-//            StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR");
-//            errorGobbler.start();
-//            StreamGobbler outGobbler = new StreamGobbler(process.getInputStream(), "STDOUT");
-//            outGobbler.start();
-//            process.waitFor();
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//        }
-//    }
 
     /**
      * 运行xx.sh 脚本

+ 0 - 61
720yun_local_manage/gis_common/src/main/java/com/gis/common/util/StreamGobbler.java

@@ -1,61 +0,0 @@
-package com.gis.common.util;
-
-import java.io.*;
-
-public class StreamGobbler extends Thread {
-
-	InputStream is;  
-    String type;  
-    OutputStream os;  
-
-    public StreamGobbler(InputStream is, String type) {  
-        this(is, type, null);  
-    }  
-
-    StreamGobbler(InputStream is, String type, OutputStream redirect) {  
-        this.is = is;  
-        this.type = type;  
-        this.os = redirect;  
-    }  
-
-    public void run() {  
-        InputStreamReader isr = null;  
-        BufferedReader br = null;  
-        PrintWriter pw = null;  
-        try {  
-            if (os != null)  
-                pw = new PrintWriter(os);  
-
-            isr = new InputStreamReader(is);  
-            br = new BufferedReader(isr);  
-            String line=null;  
-            while ( (line = br.readLine()) != null) {  
-                if (pw != null)  
-                    pw.println(line);  
-                System.out.println(type + ">" + line);
-            }  
-
-            if (pw != null)  
-                pw.flush();  
-        } catch (IOException ioe) {  
-            ioe.printStackTrace();    
-        } finally{  
-            try {  
-            	if(pw!=null)
-            	{
-            		 pw.close();  
-            	}
-            	if(br!=null)
-            	{
-            		br.close();  
-            	}
-            	if(isr!=null)
-            	{
-            		isr.close();  
-            	}
-            } catch (IOException e) {  
-                e.printStackTrace();  
-            }  
-        }  
-    }  
-}

+ 1 - 0
720yun_local_manage/gis_pano/src/main/resources/someData.json

@@ -39,5 +39,6 @@
   "remindTime": 1,
   "bgm": "",
   "guideDefaultTime": "",
+  "expandHotStyles": [],
   "status": 0
 }