deason пре 4 година
родитељ
комит
0c9603bd28

+ 1 - 1
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/AuthController.java

@@ -86,7 +86,7 @@ public class AuthController extends ControllerSupport {
 
         String isApp = request.getHeader("isApp");
         if (StringUtils.isNotEmpty(isApp) && "true".equals(isApp)) {
-            log.info("App login ... " + loginInfo.getAccountValue());
+            LOGGER.info("App login ... " + loginInfo.getAccountValue());
             user = authService.login(loginInfo, false);
         } else {
             user = authService.login(loginInfo, true);

+ 5 - 3
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/LogController.java

@@ -32,7 +32,8 @@ public class LogController extends ControllerSupport {
 
     @ApiOperation(value = "学生客户端日志")
     @PostMapping("studentClient/{level}/{code}")
-    public String logByStudentClient(@PathVariable String level, @PathVariable String code,
+    public String logByStudentClient(@PathVariable String level,
+                                     @PathVariable String code,
                                      @RequestBody String info) {
         log("STUDENT_CLIENT_LOGGER", level, code, info);
         return DateUtil.chinaNow();
@@ -49,12 +50,13 @@ public class LogController extends ControllerSupport {
      */
     private void log(String logger, String level, String code, String info) {
         if (!code.matches("\\w{1,2}\\-\\d{6}")) {
-            throw new StatusException("500002",
-                    "code must match regular expression:  \\w{1,2}\\-\\d{6}");
+            throw new StatusException("500002", "code must match regular expression:  \\w{1,2}\\-\\d{6}");
         }
+
         info = RegExUtils.replaceAll(info, "[\n\r]", "  ");
         ExamCloudLog log = getLogger(logger);
         MDC.put("CODE", code);
+
         if ("debug".equalsIgnoreCase(level)) {
             log.debug(info);
         } else if ("info".equalsIgnoreCase(level)) {

+ 1 - 1
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/OrgController.java

@@ -1422,7 +1422,7 @@ public class OrgController extends ControllerSupport {
     @GetMapping("importTemplate")
     public void getDownloadTemplate(HttpServletResponse response) {
         String resoucePath = PathUtil.getResoucePath("templates/subOrgImportTemplate.xlsx");
-        log.info("-------getDownloadTemplate-resoucePath=" + resoucePath);
+        LOGGER.info("-------getDownloadTemplate-resoucePath=" + resoucePath);
         exportFile("学习中心导入模板.xlsx", new File(resoucePath));
     }
 

+ 1 - 1
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/UserController.java

@@ -413,7 +413,7 @@ public class UserController extends ControllerSupport {
             }
 
             if (roleEntity == null) {
-                log.warn("Role not exist, code is " + roleCode);
+                LOGGER.warn("Role not exist, code is " + roleCode);
                 throw new StatusException("500404", "角色不存在");
             }
 

+ 10 - 10
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/LoginRuleServiceImpl.java

@@ -6,8 +6,6 @@
 package cn.com.qmth.examcloud.core.basic.service.impl;
 
 import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
 import cn.com.qmth.examcloud.commons.util.JsonUtil;
 import cn.com.qmth.examcloud.core.basic.dao.LoginRuleRepo;
 import cn.com.qmth.examcloud.core.basic.dao.entity.LoginRuleEntity;
@@ -23,6 +21,8 @@ import cn.com.qmth.examcloud.web.filestorage.YunPathInfo;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.*;
 import org.springframework.data.jpa.domain.Specification;
@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
 @Service
 public class LoginRuleServiceImpl implements LoginRuleService {
 
-    private static final ExamCloudLog log = ExamCloudLogFactory.getLog("INTERFACE_LOGGER");
+    private static final Logger LOG = LoggerFactory.getLogger(LoginRuleServiceImpl.class);
 
     /**
      * “登录规则”的缓存KEY前缀
@@ -187,7 +187,7 @@ public class LoginRuleServiceImpl implements LoginRuleService {
             this.uploadJsonFile(json);
         }
 
-        log.info("refreshLoginRule " + type.name());
+        LOG.info("refreshLoginRule " + type.name());
     }
 
     private void uploadJsonFile(String json) {
@@ -196,9 +196,9 @@ public class LoginRuleServiceImpl implements LoginRuleService {
             FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
             env.setExt1("geetestConfig");
             YunPathInfo oss = FileStorageUtil.saveFile(LOGIN_RULE_SITE_ID, env, json.getBytes(), true);
-            log.debug(oss.getRelativePath());
+            LOG.debug(oss.getRelativePath());
         } catch (Exception e) {
-            log.error(e.getMessage(), e);
+            LOG.error(e.getMessage(), e);
         }
     }
 
@@ -220,7 +220,7 @@ public class LoginRuleServiceImpl implements LoginRuleService {
         String cacheKey = LOGIN_RULE_CACHE_KEY_PREFIX + type.name();
         Map<String, Boolean> values = redisClient.get(cacheKey, HashMap.class);
         if (MapUtils.isEmpty(values)) {
-            log.warn(String.format("LoginRule not exist, type = %s, rootOrgId = %s", rootOrgId, type.name()));
+            LOG.warn(String.format("LoginRule not exist, type = %s, rootOrgId = %s", rootOrgId, type.name()));
             return true;
         }
 
@@ -231,17 +231,17 @@ public class LoginRuleServiceImpl implements LoginRuleService {
 
         if (globalAllow == null || globalAllow) {
             if (allow == null || allow) {
-                log.info(String.format("LoginRule allow, rootOrgId = %s, type = %s", rootOrgId, type.name()));
+                LOG.info(String.format("LoginRule allow, rootOrgId = %s, type = %s", rootOrgId, type.name()));
                 return true;
             }
         } else {
             if (allow != null && allow) {
-                log.info(String.format("LoginRule allow, rootOrgId = %s, type = %s", rootOrgId, type.name()));
+                LOG.info(String.format("LoginRule allow, rootOrgId = %s, type = %s", rootOrgId, type.name()));
                 return true;
             }
         }
 
-        log.info(String.format("LoginRule unAllow, rootOrgId = %s, type = %s", rootOrgId, type.name()));
+        LOG.info(String.format("LoginRule unAllow, rootOrgId = %s, type = %s", rootOrgId, type.name()));
         return false;
     }
 

+ 7 - 7
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/UserDataRuleServiceImpl.java

@@ -3,8 +3,6 @@ package cn.com.qmth.examcloud.core.basic.service.impl;
 import cn.com.qmth.examcloud.api.commons.enums.DataRuleType;
 import cn.com.qmth.examcloud.api.commons.security.enums.RoleMeta;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
 import cn.com.qmth.examcloud.core.basic.dao.CourseRepo;
 import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
 import cn.com.qmth.examcloud.core.basic.dao.UserDataRuleRepo;
@@ -24,6 +22,8 @@ import cn.com.qmth.examcloud.examwork.api.response.GetExamMapsResp;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.*;
 import org.springframework.data.jpa.domain.Specification;
@@ -36,7 +36,7 @@ import java.util.stream.Collectors;
 @Service
 public class UserDataRuleServiceImpl implements UserDataRuleService {
 
-    private static final ExamCloudLog log = ExamCloudLogFactory.getLog("INTERFACE_LOGGER");
+    private static final Logger LOG = LoggerFactory.getLogger(UserDataRuleServiceImpl.class);
 
     private static final String DATA_RULE_CACHE_KEY = "$DATA_RULE:%s_%s";//“数据权限”的缓存KEY规则
 
@@ -257,13 +257,13 @@ public class UserDataRuleServiceImpl implements UserDataRuleService {
         Map<Long, Long> targetUserMaps = new HashMap<>();
         for (Long targetUserId : req.getTargetUserIds()) {
             if (targetUserId.equals(req.getSourceUserId())) {
-                log.warn(String.format("跳过复制,targetUserId与sourceUserId相同... id = %s", targetUserId));
+                LOG.warn(String.format("跳过复制,targetUserId与sourceUserId相同... id = %s", targetUserId));
                 continue;
             }
 
             Optional<UserEntity> targetUser = userRepo.findById(targetUserId);
             if (!targetUser.isPresent()) {
-                log.warn(String.format("User is not exist... targetUserId = %s", targetUserId));
+                LOG.warn(String.format("User is not exist... targetUserId = %s", targetUserId));
                 continue;
             }
 
@@ -438,8 +438,8 @@ public class UserDataRuleServiceImpl implements UserDataRuleService {
             refIds.add(rule.getRefId());
         }
 
-        if (log.isInfoEnabled()) {
-            log.info(String.format("userId = %s, dataRuleType = %s, globalStatus = %s, refIds = [%s]",
+        if (LOG.isInfoEnabled()) {
+            LOG.info(String.format("userId = %s, dataRuleType = %s, globalStatus = %s, refIds = [%s]",
                     userId, type.name(), cacheBean.getGlobalStatus(), StringUtils.join(refIds, ",")));
         }
 

+ 6 - 6
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/VerifyCodeServiceImpl.java

@@ -3,8 +3,6 @@ package cn.com.qmth.examcloud.core.basic.service.impl;
 import cn.com.qmth.examcloud.api.commons.security.bean.User;
 import cn.com.qmth.examcloud.api.commons.security.bean.UserType;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
 import cn.com.qmth.examcloud.commons.util.UUID;
 import cn.com.qmth.examcloud.core.basic.base.util.VerifyCode;
 import cn.com.qmth.examcloud.core.basic.dao.enums.LoginRuleType;
@@ -22,6 +20,8 @@ import cn.com.qmth.examcloud.reports.commons.util.ReportsUtil;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -31,7 +31,7 @@ import org.springframework.stereotype.Service;
 @Service
 public class VerifyCodeServiceImpl implements VerifyCodeService {
 
-    private static final ExamCloudLog log = ExamCloudLogFactory.getLog("INTERFACE_LOGGER");
+    private static final Logger LOG = LoggerFactory.getLogger(VerifyCodeServiceImpl.class);
 
     private static final String CACHE_KEY_VERIFY_CODE = "B_VERIFY_CODE:%s_%s";// “验证码”缓存KEY
 
@@ -110,7 +110,7 @@ public class VerifyCodeServiceImpl implements VerifyCodeService {
         String base64 = Base64.encodeBase64String(bytes);
         String uuid = UUID.randomUUID();
 
-        log.info(String.format("accountValue = %s, uuid = %s, verifyCode = %s", accountValue, uuid, result.getResult()));
+        LOG.info(String.format("accountValue = %s, uuid = %s, verifyCode = %s", accountValue, uuid, result.getResult()));
         VerifyCodeCacheBean cacheBean = new VerifyCodeCacheBean();
         cacheBean.setUuid(uuid);
         cacheBean.setVerifyCode(result.getResult());
@@ -159,7 +159,7 @@ public class VerifyCodeServiceImpl implements VerifyCodeService {
         final String cacheKeyVerifyCodeResource = String.format(CACHE_KEY_VERIFY_CODE_RESOURCE, cacheBean.getUuid());
         Boolean resource = redisClient.get(cacheKeyVerifyCodeResource, Boolean.class);
         if (resource == null) {
-            log.warn(String.format("accountValue = %s, uuid = %s, Real uuid = %s", info.getAccountValue(), info.getUuid(), cacheBean.getUuid()));
+            LOG.warn(String.format("accountValue = %s, uuid = %s, Real uuid = %s", info.getAccountValue(), info.getUuid(), cacheBean.getUuid()));
             throw new StatusException("400", "验证码请求无效,请重试!");
         }
 
@@ -195,7 +195,7 @@ public class VerifyCodeServiceImpl implements VerifyCodeService {
     @Override
     public void verifyCodeResource(String uuid) {
         if (StringUtils.isBlank(uuid) || uuid.length() != 32) {
-            log.debug("Invalid uuid... " + uuid);
+            LOG.debug("Invalid uuid... " + uuid);
             return;
         }
 

+ 3 - 2
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/report/RocketMqConsumerListener.java

@@ -22,7 +22,8 @@ import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
 import cn.com.qmth.examcloud.web.support.SpringContextHolder;
 
 public class RocketMqConsumerListener {
-    private final static Logger logger = LoggerFactory.getLogger(RocketMqConsumerListener.class);
+    private static final Logger LOG = LoggerFactory.getLogger(RocketMqConsumerListener.class);
+
     private static AdminOperateService adminOperateService = SpringContextHolder.getBean(AdminOperateService.class);
     private static Properties properties = new Properties();
 
@@ -55,7 +56,7 @@ public class RocketMqConsumerListener {
                     onMessageAdminOperate(msg,message.getMsgID());
                     return Action.CommitMessage;
                 } catch (Exception e) {
-                    logger.error("consumer failed MsgID:" + message.getMsgID(), e);
+                    LOG.error("consumer failed MsgID:" + message.getMsgID(), e);
                     return Action.ReconsumeLater;
                 }
             }

+ 3 - 2
examcloud-core-basic-starter/src/main/java/cn/com/qmth/examcloud/core/basic/starter/config/MqConsumerListenerStartup.java

@@ -14,7 +14,8 @@ import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
 @Component
 @Order(999)
 public class MqConsumerListenerStartup implements ApplicationRunner {
-	private final static Logger logger = LoggerFactory.getLogger(MqConsumerListenerStartup.class);
+	private static final Logger LOG = LoggerFactory.getLogger(MqConsumerListenerStartup.class);
+
 	private void startConsumerListener() {
 
 		String mqType = PropertyHolder.getString("$report.mq-type");
@@ -25,7 +26,7 @@ public class MqConsumerListenerStartup implements ApplicationRunner {
 			if(MqType.ROCKETMQ.getCode().equals(mqType)) {
 				RocketMqConsumerListener.start();
 			}else {
-				logger.error("no $report.mq-type property config!");
+				LOG.error("no $report.mq-type property config!");
 			}
 		}
 

+ 30 - 47
examcloud-core-basic-starter/src/main/resources/log4j2.xml

@@ -2,47 +2,32 @@
 <Configuration status="WARN" monitorInterval="30">
 
     <Properties>
-        <Property name="commonLevel" value="${sys:log.commonLevel}"/>
-        <Property name="logPattern">
+        <Property name="LOG_LEVEL" value="${sys:log.commonLevel}"/>
+        <Property name="LOG_DIR" value="./logs/examcloud-core-basic"/>
+        <Property name="STUDENT_CLIENT_LOG_DIR" value="./logs/student-client"/>
+        <Property name="LOG_PATTERN">
             %d{yyyy-MM-dd HH:mm:ss.SSS} | %clr{%level} | %X{TRACE_ID} %X{CALLER} | %clr{%c{1.1}:%L}{cyan} | %m%n
         </Property>
     </Properties>
 
     <Appenders>
-        <!-- 控制台 日志 -->
-        <Console name="Console" target="SYSTEM_OUT">
-            <PatternLayout pattern="${logPattern}" charset="UTF-8"/>
+        <Console name="CONSOLE_APPENDER" target="SYSTEM_OUT">
+            <PatternLayout pattern="${LOG_PATTERN}" charset="UTF-8"/>
         </Console>
 
-        <!-- debug 日志 -->
-        <RollingFile name="DEBUG_APPENDER"
-                     fileName="./logs/debug/debug.log"
-                     filePattern="./logs/debug/debug-%d{yyyy.MM.dd.HH}-%i.log">
-            <PatternLayout pattern="${logPattern}" charset="UTF-8"/>
-            <Policies>
-                <TimeBasedTriggeringPolicy interval="1" modulate="false"/>
-                <SizeBasedTriggeringPolicy size="100 MB"/>
-            </Policies>
-            <DefaultRolloverStrategy max="1000">
-                <Delete basePath="./logs/debug" maxDepth="1">
-                    <IfFileName glob="debug-*.log">
-                        <IfAccumulatedFileSize exceeds="2 GB"/>
-                    </IfFileName>
-                </Delete>
-            </DefaultRolloverStrategy>
-        </RollingFile>
+        <RollingFile name="FILE_APPENDER"
+                     fileName="${LOG_DIR}/debug.log"
+                     filePattern="${LOG_DIR}/debug-%d{yyyyMMdd}-%i.log">
+            <PatternLayout pattern="${LOG_PATTERN}" charset="UTF-8"/>
 
-        <!-- 接口日志 -->
-        <RollingFile name="INTERFACE_APPENDER" fileName="./logs/interface/interface.log"
-                     filePattern="./logs/interface/interface-%d{yyyy.MM.dd.HH}-%i.log">
-            <PatternLayout pattern="${logPattern}" charset="UTF-8"/>
             <Policies>
                 <TimeBasedTriggeringPolicy interval="1" modulate="false"/>
                 <SizeBasedTriggeringPolicy size="100 MB"/>
             </Policies>
+
             <DefaultRolloverStrategy max="1000">
-                <Delete basePath="./logs/interface" maxDepth="1">
-                    <IfFileName glob="interface-*.log">
+                <Delete basePath="${LOG_DIR}" maxDepth="1">
+                    <IfFileName glob="debug-*.log">
                         <IfAccumulatedFileSize exceeds="10 GB"/>
                     </IfFileName>
                 </Delete>
@@ -50,17 +35,20 @@
         </RollingFile>
 
         <!-- 考生客户端日志 -->
-        <RollingFile name="STUDENT_CLIENT_APPENDER" fileName="./logs/student_client/student_client.log"
-                     filePattern="./logs/student_client/student_client-%d{yyyy.MM.dd}-%i.log">
-            <PatternLayout pattern="${logPattern}" charset="UTF-8"/>
+        <RollingFile name="STUDENT_CLIENT_APPENDER"
+                     fileName="${STUDENT_CLIENT_LOG_DIR}/debug.log"
+                     filePattern="${STUDENT_CLIENT_LOG_DIR}/debug-%d{yyyyMMdd}-%i.log">
+            <PatternLayout pattern="${LOG_PATTERN}" charset="UTF-8"/>
+
             <Policies>
                 <TimeBasedTriggeringPolicy interval="1" modulate="false"/>
                 <SizeBasedTriggeringPolicy size="100 MB"/>
             </Policies>
+
             <DefaultRolloverStrategy max="1000">
-                <Delete basePath="./logs/student_client" maxDepth="1">
-                    <IfFileName glob="student_client-*.log">
-                        <IfAccumulatedFileSize exceeds="5 GB"/>
+                <Delete basePath="${STUDENT_CLIENT_LOG_DIR}" maxDepth="1">
+                    <IfFileName glob="debug-*.log">
+                        <IfAccumulatedFileSize exceeds="10 GB"/>
                     </IfFileName>
                 </Delete>
             </DefaultRolloverStrategy>
@@ -84,24 +72,19 @@
         <!--<logger name="org.springframework.data.mongodb" level="DEBUG"/>-->
         <!--<logger name="org.springframework.data.redis" level="DEBUG"/>-->
 
-        <Logger name="cn.com.qmth" level="${commonLevel}" additivity="false">
-            <AppenderRef ref="DEBUG_APPENDER"/>
-            <AppenderRef ref="Console"/>
-        </Logger>
-
-        <Logger name="INTERFACE_LOGGER" level="${commonLevel}" additivity="false">
-            <AppenderRef ref="INTERFACE_APPENDER"/>
-            <AppenderRef ref="Console"/>
+        <Logger name="cn.com.qmth" level="${LOG_LEVEL}" additivity="false">
+            <AppenderRef ref="CONSOLE_APPENDER"/>
+            <AppenderRef ref="FILE_APPENDER"/>
         </Logger>
 
-        <Logger name="STUDENT_CLIENT_LOGGER" level="${commonLevel}" additivity="false">
+        <Logger name="STUDENT_CLIENT_LOGGER" level="${LOG_LEVEL}" additivity="false">
+            <AppenderRef ref="CONSOLE_APPENDER"/>
             <AppenderRef ref="STUDENT_CLIENT_APPENDER"/>
-            <AppenderRef ref="Console"/>
         </Logger>
 
-        <Root level="${commonLevel}">
-            <AppenderRef ref="Console"/>
-            <AppenderRef ref="DEBUG_APPENDER"/>
+        <Root level="${LOG_LEVEL}">
+            <AppenderRef ref="CONSOLE_APPENDER"/>
+            <AppenderRef ref="FILE_APPENDER"/>
         </Root>
     </Loggers>