瀏覽代碼

update logger

deason 3 年之前
父節點
當前提交
83fc98dc87

+ 1 - 5
examcloud-core-oe-task-service/src/main/java/cn/com/qmth/examcloud/core/oe/task/service/impl/ExamCaptureQueueServiceImpl.java

@@ -11,8 +11,6 @@ import cn.com.qmth.examcloud.core.oe.task.service.bean.SaveExamCaptureQueueInfo;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
 import cn.com.qmth.examcloud.support.cache.bean.StudentCacheBean;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,8 +29,6 @@ public class ExamCaptureQueueServiceImpl implements ExamCaptureQueueService {
 
     private static final Logger log = LoggerFactory.getLogger(ExamCaptureQueueServiceImpl.class);
 
-    private final Log captureLog = LogFactory.getLog("PROCESS_EXAM_CAPTURE_TASK_LOGGER");
-
     @Autowired
     private ExamCaptureQueueRepo examCaptureQueueRepo;
 
@@ -44,7 +40,7 @@ public class ExamCaptureQueueServiceImpl implements ExamCaptureQueueService {
                     "000000", new Date());
             return true;
         } catch (Exception e) {
-            captureLog.error("[UPDATE_FAILED_CAPTURE_QUEUE] 保存照片队列处理失败数据时出现异常", e);
+            log.error("[UPDATE_FAILED_CAPTURE_QUEUE] 保存照片队列处理失败数据时出现异常", e);
             return false;
         }
     }

+ 24 - 28
examcloud-core-oe-task-service/src/main/java/cn/com/qmth/examcloud/core/oe/task/service/impl/ExamCaptureServiceImpl.java

@@ -28,8 +28,6 @@ import cn.com.qmth.examcloud.web.redis.RedisClient;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.json.JSONException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -54,8 +52,6 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
 
     private static final Logger log = LoggerFactory.getLogger(ExamCaptureServiceImpl.class);
 
-    private final Log captureLog = LogFactory.getLog("PROCESS_EXAM_CAPTURE_TASK_LOGGER");
-
     @Autowired
     private ExamCaptureRepo examCaptureRepo;
 
@@ -96,7 +92,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
 
             //仅用于日志时间计算
             long startTime = System.currentTimeMillis();
-            captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对开始...");
+            log.debug("[DISPOSE_FACE_COMPARE] face++人脸比对开始...");
 
             //调用face++API执行人脸比对,得到返回结果
             JsonHttpResponseHolder jsonHttpResponseHolder = null;
@@ -114,14 +110,14 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                     examCaptureQueue.setFaceCompareResult(e.getDesc());
                     saveExamCaptureAndDeleteQueue(examCaptureQueue);
 
-                    captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对无法处理的图片地址,保存人脸检测最终结果并删除队列,errMsg=" + e.getDesc());
+                    log.debug("[DISPOSE_FACE_COMPARE] face++人脸比对无法处理的图片地址,保存人脸检测最终结果并删除队列,errMsg=" + e.getDesc());
                     return;
                 }
                 throw e;
             }
 
-            if (captureLog.isDebugEnabled()) {
-                captureLog.debug("[DISPOSE_FACE_COMPARE] 调用face++API执行人脸比对,得到返回结果faceCompareResult:" + faceCompareResult);
+            if (log.isDebugEnabled()) {
+                log.debug("[DISPOSE_FACE_COMPARE] 调用face++API执行人脸比对,得到返回结果faceCompareResult:" + faceCompareResult);
             }
             examCaptureQueue.setFaceCompareResult(faceCompareResult.toString());
 
@@ -132,7 +128,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                 //如果API并发次数超过上限,则保存错误信息到队列,并抛出异常,用于协调满载队列线程
                 if (errMsg.contains(Constants.FACE_COMPARE_CONCURRENCY_LIMIT_EXCEEDED)) {
 
-                    captureLog.error("[FaceCompareQueue] FacePlusPlus_QPS_CONCURRENCY_LIMITED");
+                    log.error("[FaceCompareQueue] FacePlusPlus_QPS_CONCURRENCY_LIMITED");
 
                     examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue.getId(),
                             "SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceCompareResult.toString(),
@@ -153,7 +149,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                     if (errMsg.contains(notRetryErrMsgsArr[i])) {
                         saveExamCaptureAndDeleteQueue(examCaptureQueue);
 
-                        captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对无法处理的图片,保存人脸检测最终结果并删除队列,errMsg=" + errMsg);
+                        log.debug("[DISPOSE_FACE_COMPARE] face++人脸比对无法处理的图片,保存人脸检测最终结果并删除队列,errMsg=" + errMsg);
 
                         return;
                     }
@@ -163,7 +159,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                 if (errMsg.contains(Constants.FACE_COMPARE_IMAGE_DOWNLOAD_TIMEOUT)) {
                     faceCompareTimeOutTimes++;
 
-                    captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对超时,将进行第" + faceCompareTimeOutTimes + "次重试");
+                    log.debug("[DISPOSE_FACE_COMPARE] face++人脸比对超时,将进行第" + faceCompareTimeOutTimes + "次重试");
 
                     //如果没有达到最大重试次数,则继续重试
                     if (faceCompareTimeOutTimes < maxRetryTimes) {
@@ -173,17 +169,17 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                     //超过最大重试次数,则直接保存最终结果
                     saveExamCaptureAndDeleteQueue(examCaptureQueue);
 
-                    captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对超过最大检测次数:" + maxRetryTimes + ",停止重试,直接保存最终结果");
+                    log.debug("[DISPOSE_FACE_COMPARE] face++人脸比对超过最大检测次数:" + maxRetryTimes + ",停止重试,直接保存最终结果");
                     return;
                 }
 
-                captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对出现错误,即将重试,errMsg:" + errMsg);
+                log.debug("[DISPOSE_FACE_COMPARE] face++人脸比对出现错误,即将重试,errMsg:" + errMsg);
                 // 其它错误类型,保存错误信息到队列中,待自动重新服务处理
                 examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue.getId(),
                         "SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceCompareResult.toString(),
                         ExamCaptureQueueStatus.PROCESS_FACE_COMPARE_FAILED);
                 ExamCaptureProcessStatisticController.increaseFaceCompareFailedCount();//增加错误次数
-                captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对出现错误,增加错误次数后failedCount:" +
+                log.debug("[DISPOSE_FACE_COMPARE] face++人脸比对出现错误,增加错误次数后failedCount:" +
                         ExamCaptureProcessStatisticController.getFaceCompareFailedCount() + ",totalCount=" +
                         ExamCaptureProcessStatisticController.getFaceCompareCount());
             }
@@ -198,7 +194,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                     examCaptureQueue.setStatus(ExamCaptureQueueStatus.PROCESS_FACE_COMPARE_COMPLETE);
                     disposeFaceCompareSuccessful(examCaptureQueue);
 
-                    captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对完成,即将进行百度活体检测,耗时:" + (System.currentTimeMillis() - startTime) + " ms");
+                    log.debug("[DISPOSE_FACE_COMPARE] face++人脸比对完成,即将进行百度活体检测,耗时:" + (System.currentTimeMillis() - startTime) + " ms");
                 }
                 //face++ 没有检测到人脸,直接保存人脸检测最终结果并删除队列
                 else {
@@ -206,7 +202,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                     examCaptureQueue.setStranger(false);
                     saveExamCaptureAndDeleteQueue(examCaptureQueue);
 
-                    captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对完成,且未检测到人脸,耗时:" + (System.currentTimeMillis() - startTime) + " ms");
+                    log.debug("[DISPOSE_FACE_COMPARE] face++人脸比对完成,且未检测到人脸,耗时:" + (System.currentTimeMillis() - startTime) + " ms");
                 }
             }
         } while (retry);
@@ -239,7 +235,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
 
             //仅用于日志时间计算
             long startTime = System.currentTimeMillis();
-            captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测开始...");
+            log.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测开始...");
 
             //获取百度活检结果
             JsonHttpResponseHolder jsonHttpResponseHolder = null;
@@ -254,7 +250,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                     examCaptureQueue.setFacelivenessResult(e.getDesc());
                     saveExamCaptureAndDeleteQueue(examCaptureQueue);
 
-                    captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活检无法处理的图片地址,保存人脸检测最终结果并删除队列,errMsg=" + e.getDesc());
+                    log.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活检无法处理的图片地址,保存人脸检测最终结果并删除队列,errMsg=" + e.getDesc());
                     return;
                 }
                 throw e;
@@ -268,7 +264,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
 
                 //如果API并发次数超过上限,则保存错误信息到队列,并抛出异常,用于协调满载队列线程
                 if (errCode.equals(Constants.BAIDU_FACELIVENESS_QPS_LIMIT_EXCEEDED_CODE)) {
-                    captureLog.error("[FaceLivenessQueue] Baidu_QPS_CONCURRENCY_LIMITED");
+                    log.error("[FaceLivenessQueue] Baidu_QPS_CONCURRENCY_LIMITED");
 
                     examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue.getId(),
                             "SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceLivenessResultJson.toString(),
@@ -287,7 +283,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                 for (int i = 0; i < notRetryErrMsgsArr.length; i++) {
                     //如果是配置中的无法处理的图片,则保存人脸检测最终结果并删除队列
                     if (errCode.equals(notRetryErrMsgsArr[i])) {
-                        captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测,无法处理的图片,将保存人脸检测最终结果并删除队列,errCode=" + errCode);
+                        log.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测,无法处理的图片,将保存人脸检测最终结果并删除队列,errCode=" + errCode);
 
                         saveExamCaptureAndDeleteQueue(examCaptureQueue);
                         return;
@@ -298,7 +294,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                 if (errCode.equals(Constants.BAIDU_FACELIVENESS_CONNECTION_OR_READ_DATA_TIME_OUT_CODE)) {
                     facelivenessTimeOutTimes++;
 
-                    captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测超时,将进行第" + facelivenessTimeOutTimes + "次重试");
+                    log.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测超时,将进行第" + facelivenessTimeOutTimes + "次重试");
 
                     //如果没有达到最大重试次数,则继续重试
                     if (facelivenessTimeOutTimes < maxRetryTimes) {
@@ -309,23 +305,23 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                     //超过最大重试次数,则直接保存最终结果
                     saveExamCaptureAndDeleteQueue(examCaptureQueue);
 
-                    captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测超过最大检测次数:" + maxRetryTimes + ",停止重试,直接保存最终结果");
+                    log.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测超过最大检测次数:" + maxRetryTimes + ",停止重试,直接保存最终结果");
                     return;
                 }
 
-                captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测出现错误,即将重试,错误码:" + errCode);
+                log.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测出现错误,即将重试,错误码:" + errCode);
                 // 其它错误类型,保存错误信息到队列中,待自动重新服务处理
                 examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue.getId(),
                         "SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceLivenessResultJson.toString(), ExamCaptureQueueStatus.PROCESS_FACELIVENESS_FAILED);
                 ExamCaptureProcessStatisticController.increaseFaceLivenessDetectFailedCount();//增加错误次数
-                captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测出现错误,增加错误次数后failedCount:" + ExamCaptureProcessStatisticController.getFaceLivenessDetectFailedCount());
+                log.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测出现错误,增加错误次数后failedCount:" + ExamCaptureProcessStatisticController.getFaceLivenessDetectFailedCount());
             }
             //百度活体检测成功,则保存最终检测结果,并删除临时的图片处理队列
             else {
                 examCaptureQueue.setFacelivenessResult(faceLivenessResultJson.toString());
                 saveExamCaptureAndDeleteQueue(examCaptureQueue);
 
-                captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测完成,耗时:" + (System.currentTimeMillis() - startTime) + " ms");
+                log.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测完成,耗时:" + (System.currentTimeMillis() - startTime) + " ms");
             }
         } while (retry);
     }
@@ -373,7 +369,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                 compareFaceSyncInfo.setExistsSystemError(true);
                 compareFaceSyncInfo.setErrorMsg(e.getDesc());
 
-                captureLog.error("[COMPARE_FACE_SYNC] face++人脸比对无法处理的图片地址,errMsg=" + e.getDesc(), e);
+                log.error("[COMPARE_FACE_SYNC] face++人脸比对无法处理的图片地址,errMsg=" + e.getDesc(), e);
                 return compareFaceSyncInfo;
             }
             throw e;
@@ -382,7 +378,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
             compareFaceSyncInfo.setExistsSystemError(true);
             compareFaceSyncInfo.setErrorMsg("系统异常");
 
-            captureLog.error("[COMPARE_FACE_SYNC] 未处理的系统异常,errMsg=" + e.getMessage(), e);
+            log.error("[COMPARE_FACE_SYNC] 未处理的系统异常,errMsg=" + e.getMessage(), e);
             return compareFaceSyncInfo;
         }
         if (facePPResult.containsKey(Constants.ERROR_MSG)) {
@@ -393,7 +389,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                 compareFaceSyncInfo.setExistsSystemError(true);
             }
             if (errMsg.contains(Constants.FACE_COMPARE_CONCURRENCY_LIMIT_EXCEEDED)) {
-                captureLog.error("[FaceCompare] FacePlusPlus_QPS_CONCURRENCY_LIMITED");
+                log.error("[FaceCompare] FacePlusPlus_QPS_CONCURRENCY_LIMITED");
                 compareFaceSyncInfo.setExistsSystemError(true);
             }
             compareFaceSyncInfo.setErrorMsg("facePP called failed : " + facePPResult.toString());

+ 8 - 8
examcloud-core-oe-task-service/src/main/java/cn/com/qmth/examcloud/core/oe/task/service/worker/BaiduFaceLivenessWorker.java

@@ -11,9 +11,9 @@ import cn.com.qmth.examcloud.core.oe.task.service.ExamCaptureService;
 import cn.com.qmth.examcloud.core.oe.task.service.bean.ExamCaptureQueueInfo;
 import cn.com.qmth.examcloud.support.Constants;
 import cn.com.qmth.examcloud.web.support.SpringContextHolder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.logging.log4j.ThreadContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.concurrent.TimeUnit;
 
@@ -24,15 +24,15 @@ import java.util.concurrent.TimeUnit;
  */
 public class BaiduFaceLivenessWorker implements Worker<ExamCaptureQueueInfo> {
 
-    private final Log captureLog = LogFactory.getLog("PROCESS_EXAM_CAPTURE_TASK_LOGGER");
+    private static final Logger log = LoggerFactory.getLogger(BaiduFaceLivenessWorker.class);
 
     @Override
     public void process(WorkerController controller, ExamCaptureQueueInfo element) {
         ThreadContext.put("TRACE_ID", "Q_" + element.getId());
         ThreadContext.put("CALLER", "BAIDU_WORKER");
         ExamCaptureProcessStatisticController.increaseFaceLivenessDetectCount();
-        if (captureLog.isDebugEnabled()) {
-            captureLog.debug("[BAIDU_FACELIVENESS_WORKER.] 图片处理数量+1,count= "
+        if (log.isDebugEnabled()) {
+            log.debug("[BAIDU_FACELIVENESS_WORKER.] 图片处理数量+1,count= "
                     + ExamCaptureProcessStatisticController.getFaceLivenessDetectCount());
         }
         ExamCaptureService examCaptureService = SpringContextHolder
@@ -54,10 +54,10 @@ public class BaiduFaceLivenessWorker implements Worker<ExamCaptureQueueInfo> {
             if ((e.getCode().equals(Constants.BAIDU_FACELIVENESS_QPS_LIMIT_EXCEEDED_CODE))) {
                 // 如果超过并发次数,则添加异常次数
                 controller.addConcurrencyWarn();
-                captureLog.debug("[BAIDU_FACELIVENESS_WORKER.] 超过并发次数 ");
+                log.debug("[BAIDU_FACELIVENESS_WORKER.] 超过并发次数 ");
             } else {
                 ExamCaptureProcessStatisticController.increaseFaceLivenessDetectCount();
-                captureLog.error("[BAIDU_FACELIVENESS_WORKER.] 自定义异常 " + e.getDesc(), e);
+                log.error("[BAIDU_FACELIVENESS_WORKER.] 自定义异常 " + e.getDesc(), e);
             }
             Util.sleep(TimeUnit.MICROSECONDS, 50);
         } catch (Exception e) {
@@ -71,7 +71,7 @@ public class BaiduFaceLivenessWorker implements Worker<ExamCaptureQueueInfo> {
                 ;
                 Util.sleep(TimeUnit.MILLISECONDS, 500);
             }
-            captureLog.error("[BAIDU_FACELIVENESS_WORKER.] 系统异常 " + e.getMessage(), e);
+            log.error("[BAIDU_FACELIVENESS_WORKER.] 系统异常 " + e.getMessage(), e);
             Util.sleep(TimeUnit.MICROSECONDS, 50);
         } finally {
             ThreadContext.clearAll();

+ 8 - 8
examcloud-core-oe-task-service/src/main/java/cn/com/qmth/examcloud/core/oe/task/service/worker/FacePPCompareWorker.java

@@ -11,9 +11,9 @@ import cn.com.qmth.examcloud.core.oe.task.service.ExamCaptureService;
 import cn.com.qmth.examcloud.core.oe.task.service.bean.ExamCaptureQueueInfo;
 import cn.com.qmth.examcloud.support.Constants;
 import cn.com.qmth.examcloud.web.support.SpringContextHolder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.logging.log4j.ThreadContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.concurrent.TimeUnit;
 
@@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit;
  */
 public class FacePPCompareWorker implements Worker<ExamCaptureQueueInfo> {
 
-    private final Log captureLog = LogFactory.getLog("PROCESS_EXAM_CAPTURE_TASK_LOGGER");
+    private static final Logger log = LoggerFactory.getLogger(FacePPCompareWorker.class);
 
     @Override
     public void process(WorkerController controller, ExamCaptureQueueInfo element) {
@@ -33,8 +33,8 @@ public class FacePPCompareWorker implements Worker<ExamCaptureQueueInfo> {
         ThreadContext.put("CALLER", "FACEPP_WORKER");
         // 图片处理数量+1
         ExamCaptureProcessStatisticController.increaseFaceCompareCount();
-        if (captureLog.isDebugEnabled()) {
-            captureLog.debug("[FACEPP_COMPARE_WORKER.] 图片处理数量+1,count= "
+        if (log.isDebugEnabled()) {
+            log.debug("[FACEPP_COMPARE_WORKER.] 图片处理数量+1,count= "
                     + ExamCaptureProcessStatisticController.getFaceCompareCount());
         }
         ExamCaptureService examCaptureService = SpringContextHolder
@@ -57,10 +57,10 @@ public class FacePPCompareWorker implements Worker<ExamCaptureQueueInfo> {
             if ((e.getCode().equals(Constants.FACE_COMPARE_CONCURRENCY_LIMIT_EXCEEDED))) {
                 // 如果超过并发次数,则添加异常次数
                 controller.addConcurrencyWarn();
-                captureLog.debug("[FACEPP_COMPARE_WORKER.] 超过并发次数 ");
+                log.debug("[FACEPP_COMPARE_WORKER.] 超过并发次数 ");
             } else {
                 ExamCaptureProcessStatisticController.increaseFaceCompareFailedCount();
-                captureLog.error("[FACEPP_COMPARE_WORKER.] 自定义异常 " +
+                log.error("[FACEPP_COMPARE_WORKER.] 自定义异常 " +
                         ",failedCount=" + ExamCaptureProcessStatisticController.getFaceCompareFailedCount(), e);
             }
 
@@ -76,7 +76,7 @@ public class FacePPCompareWorker implements Worker<ExamCaptureQueueInfo> {
                 }
                 Util.sleep(TimeUnit.MILLISECONDS, 500);
             }
-            captureLog.error("[FACEPP_COMPARE_WORKER.] 系统异常 " +
+            log.error("[FACEPP_COMPARE_WORKER.] 系统异常 " +
                     ",failedCount=" + ExamCaptureProcessStatisticController.getFaceCompareFailedCount(), e);
             Util.sleep(TimeUnit.MICROSECONDS, 50);
         } finally {