Просмотр исходного кода

修改日志配置;优化异常处理

Huanyi 1 день назад
Родитель
Сommit
bded2c7fde

+ 4 - 0
ruoyi-admin/src/main/resources/application-dev.yml

@@ -1,3 +1,7 @@
+--- # 日志配置
+logging:
+  config: classpath:logback-plus-dev.xml
+
 --- # 验证码配置
 captcha:
   # 是否启用验证码校验

+ 5 - 1
ruoyi-admin/src/main/resources/application-prod.yml

@@ -1,5 +1,9 @@
 --- # 临时文件存储位置 避免临时文件被系统清理报错
-spring.servlet.multipart.location: /ruoyi/server/temp
+spring.servlet.multipart.location: ./temp
+
+--- # 日志配置
+logging:
+  config: classpath:logback-plus-prod.xml
 
 --- # 验证码配置
 captcha:

+ 0 - 1
ruoyi-admin/src/main/resources/application.yml

@@ -27,7 +27,6 @@ logging:
     org.springframework: warn
     org.mybatis.spring.mapper: error
     org.apache.fury: warn
-  config: classpath:logback-plus.xml
 
 # 用户配置
 user:

+ 18 - 0
ruoyi-admin/src/main/resources/logback-plus-dev.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+    <property name="console.log.pattern"
+              value="%cyan(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}%n) - %msg%n"/>
+
+    <!-- 控制台输出(dev 仅输出到控制台,不写日志文件) -->
+    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>${console.log.pattern}</pattern>
+            <charset>utf-8</charset>
+        </encoder>
+    </appender>
+
+    <root level="info">
+        <appender-ref ref="console" />
+    </root>
+
+</configuration>

+ 0 - 0
ruoyi-admin/src/main/resources/logback-plus.xml → ruoyi-admin/src/main/resources/logback-plus-prod.xml


+ 2 - 2
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysConfigServiceImpl.java

@@ -134,7 +134,7 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
         if (row > 0) {
             return config.getConfigValue();
         }
-        throw new ServiceException("操作失败");
+        throw new RuntimeException("操作失败");
     }
 
     /**
@@ -162,7 +162,7 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
         if (row > 0) {
             return config.getConfigValue();
         }
-        throw new ServiceException("操作失败");
+        throw new RuntimeException("操作失败");
     }
 
     /**

+ 2 - 3
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDictDataServiceImpl.java

@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.RequiredArgsConstructor;
 import org.dromara.common.core.constant.CacheNames;
-import org.dromara.common.core.exception.ServiceException;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.PageQuery;
@@ -121,7 +120,7 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
         if (row > 0) {
             return baseMapper.selectDictDataByType(data.getDictType());
         }
-        throw new ServiceException("操作失败");
+        throw new RuntimeException("操作失败");
     }
 
     /**
@@ -138,7 +137,7 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
         if (row > 0) {
             return baseMapper.selectDictDataByType(data.getDictType());
         }
-        throw new ServiceException("操作失败");
+        throw new RuntimeException("操作失败");
     }
 
     /**

+ 2 - 2
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDictTypeServiceImpl.java

@@ -177,7 +177,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
             // 新增 type 下无 data 数据 返回空防止缓存穿透
             return new ArrayList<>();
         }
-        throw new ServiceException("操作失败");
+        throw new RuntimeException("新增字典类型失败");
     }
 
     /**
@@ -201,7 +201,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
             CacheUtils.evict(CacheNames.SYS_DICT_TYPE, oldDict.getDictType());
             return dictDataMapper.selectDictDataByType(dict.getDictType());
         }
-        throw new ServiceException("操作失败");
+        throw new RuntimeException("操作失败");
     }
 
     /**

+ 1 - 1
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java

@@ -202,7 +202,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
         try {
             uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType());
         } catch (IOException e) {
-            throw new ServiceException(e.getMessage());
+            throw new RuntimeException(e);
         }
         SysOssExt ext1 = new SysOssExt();
         ext1.setFileSize(file.getSize());

+ 1 - 1
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysTenantServiceImpl.java

@@ -129,7 +129,7 @@ public class SysTenantServiceImpl implements ISysTenantService {
         add.setTenantId(tenantId);
         boolean flag = baseMapper.insert(add) > 0;
         if (!flag) {
-            throw new ServiceException("创建租户失败");
+            throw new RuntimeException("创建租户失败");
         }
         bo.setId(add.getId());
 

+ 2 - 2
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java

@@ -539,7 +539,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
         // 防止更新失败导致的数据删除
         int flag = baseMapper.deleteById(userId);
         if (flag < 1) {
-            throw new ServiceException("删除用户失败!");
+            throw new RuntimeException("删除用户失败!");
         }
         return flag;
     }
@@ -565,7 +565,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
         // 防止更新失败导致的数据删除
         int flag = baseMapper.deleteByIds(ids);
         if (flag < 1) {
-            throw new ServiceException("删除用户失败!");
+            throw new RuntimeException("删除用户失败!");
         }
         return flag;
     }

+ 0 - 0
ruoyi-modules/yingpaipay-erp/src/main/resources/mapper/.gitkeep