Ver Fonte

新增 日志打印后存入数据库的功能

liu há 1 mês atrás
pai
commit
00a00bb90a
23 ficheiros alterados com 507 adições e 216 exclusões
  1. BIN
      db/unidia206.db
  2. 19 18
      src/main/java/com/bfkj/unidia/Core/DataServices.java
  3. 43 42
      src/main/java/com/bfkj/unidia/Core/ServiceController.java
  4. 9 8
      src/main/java/com/bfkj/unidia/DataBaseUtils/ConnectionPoolManager.java
  5. 9 8
      src/main/java/com/bfkj/unidia/DataBaseUtils/DbExecutor.java
  6. 0 2
      src/main/java/com/bfkj/unidia/DataBaseUtils/DbParamsService.java
  7. 2 1
      src/main/java/com/bfkj/unidia/DataBaseUtils/DbUtils.java
  8. 9 11
      src/main/java/com/bfkj/unidia/DataBaseUtils/JdbcExecutor.java
  9. 9 8
      src/main/java/com/bfkj/unidia/DataBaseUtils/TableStructureManager.java
  10. 5 4
      src/main/java/com/bfkj/unidia/DataUtils/DataFormatConverter.java
  11. 23 22
      src/main/java/com/bfkj/unidia/DataUtils/ScriptExecutor.java
  12. 11 10
      src/main/java/com/bfkj/unidia/IOUtils/ActiveMQHelper.java
  13. 2 1
      src/main/java/com/bfkj/unidia/IOUtils/HttpHelper.java
  14. 35 34
      src/main/java/com/bfkj/unidia/IOUtils/IBMMQHelper.java
  15. 16 15
      src/main/java/com/bfkj/unidia/IOUtils/KafkaHelper.java
  16. 9 8
      src/main/java/com/bfkj/unidia/IOUtils/RabbitMQHelper.java
  17. 7 6
      src/main/java/com/bfkj/unidia/IOUtils/RocketMQHelper.java
  18. 4 3
      src/main/java/com/bfkj/unidia/OpenApi/DataProcessApi.java
  19. 2 1
      src/main/java/com/bfkj/unidia/OpenApi/ServiceControllerApi.java
  20. 15 12
      src/main/java/com/bfkj/unidia/SystemEnvInitializer.java
  21. 3 2
      src/main/java/com/bfkj/unidia/cacheUtils/CacheUtil.java
  22. 250 0
      src/main/java/com/bfkj/unidia/logUtils/Log.java
  23. 25 0
      src/main/java/com/bfkj/unidia/logUtils/SpringContextHolder.java

BIN
db/unidia206.db


+ 19 - 18
src/main/java/com/bfkj/unidia/Core/DataServices.java

@@ -5,6 +5,7 @@ import com.bfkj.unidia.DataBaseUtils.DbExecutor;
 import com.bfkj.unidia.DataUtils.DataFormatConverter;
 import com.bfkj.unidia.DataUtils.ScriptExecutor;
 import com.bfkj.unidia.Result;
+import com.bfkj.unidia.logUtils.Log;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,13 +47,13 @@ public class DataServices {
         long startTime = System.nanoTime();
         // 1. 验证参数并获取服务信息
         if (!params.containsKey("service_code")) {
-            logger.error("缺少必要参数: service_code:[{}]", params);
+            Log.error("缺少必要参数: service_code:[{}]", params);
             return Result.fail("缺少必要参数: service_code");
         }
         String serviceCode = (String) params.get("service_code");
         Result<ServiceInfo> serviceInfoResult = getServiceInfo(serviceCode);
         if (!serviceInfoResult.isSuccess()) {
-            logger.error("获取服务信息失败: {};params:[{}]",serviceInfoResult.getError(), params);
+            Log.error("获取服务信息失败: {};params:[{}]",serviceInfoResult.getError(), params);
             return Result.fail("获取服务信息失败: " + serviceInfoResult.getError());
         }
         ServiceInfo serviceInfo = serviceInfoResult.getData();
@@ -66,7 +67,7 @@ public class DataServices {
         // 3. 获取并排序算法配置
         Result<List<AlgorithmConfig>> algorithmResult = getAlgorithmConfigs(serviceCode);
         if (!algorithmResult.isSuccess()) {
-            logger.error("获取算法配置失败: {}", algorithmResult.getError());
+            Log.error("获取算法配置失败: {}", algorithmResult.getError());
             return Result.fail("获取算法配置失败: " + algorithmResult.getError());
         }
         List<AlgorithmConfig> algorithms = algorithmResult.getData().stream()
@@ -75,13 +76,13 @@ public class DataServices {
         // 4. 执行算法调度
         Result<Void> executionResult = executeAlgorithms(context, algorithms);
         if (!executionResult.isSuccess()) {//异步异常数据库日志
-            logger.error("算法执行失败: {}",executionResult.getError());
+            Log.error("算法执行失败: {}",executionResult.getError());
             return Result.fail("算法执行失败: " + executionResult.getError());
         }
         // 5. 构建返回结果
         Map<String, Object> result = buildResult(context, serviceInfo);
         if(serviceInfo.logEnable()){//异步正常数据库日志
-            logger.info("服务执行完成: {},总耗时:{}",result, System.currentTimeMillis() - startTime);
+            Log.info("服务执行完成: {},总耗时:{}",result, System.currentTimeMillis() - startTime);
         }
         return Result.success(result);
     }
@@ -99,16 +100,16 @@ public class DataServices {
             // 1. 检查前置条件
             Result<Integer> conditionResult = evaluatePrecondition(context, config);
             if (!conditionResult.isSuccess()) {
-                logger.error("前置条件评估失败:{} ", conditionResult.getError());
+                Log.error("前置条件评估失败:{} " ,context,algorithms);
                 return Result.fail("前置条件评估失败: " + conditionResult.getError());
             }
             // 前置条件执行的结果
             int conditionValue = conditionResult.getData();
             if (conditionValue == 1) { // 跳过当前算法
-                logger.info("跳过算法: " + config.algorithmCode());
+                Log.info("跳过算法: " + config.algorithmCode());
                 continue;
             } else if (conditionValue == 2) { // 跳过当前及后续算法
-                logger.info("跳过算法及后续算法: " + config.algorithmCode());
+                Log.info("跳过算法及后续算法: " + config.algorithmCode());
                 break;
             }
             // 2. 准备输入参数  {"dataList":"@0010.returnData"} ,  {"0010":{"xx":消费到的数据集合}} ,
@@ -116,7 +117,7 @@ public class DataServices {
             // 3. 执行算法
             Result<Map<String, Object>> executionResult = executeAlgorithm(config, inputData);
             if (!executionResult.isSuccess()) {
-                logger.error("算法执行失败: " + executionResult.getError());
+                Log.error("算法执行失败: " + executionResult.getError(),context,algorithms);
                 return Result.fail("算法执行失败: " + executionResult.getError());
             }
             Map<String, Object> resultData = executionResult.getData();
@@ -124,7 +125,7 @@ public class DataServices {
             // 4. 处理结果存储
             Result<Void> saveResult = handleResultStorage(context, config, resultData);
             if (!saveResult.isSuccess()) {
-                logger.error("结果存储失败: " + saveResult.getError());
+                Log.error("结果存储失败: " + saveResult.getError(),context,algorithms);
                 return Result.fail("结果存储失败: " + saveResult.getError());
             }
         }
@@ -343,19 +344,19 @@ public class DataServices {
                             row.put("last_value", rs.getString("last_value"));
                             return row;
                         } catch (Exception e) {
-                            logger.error("获取系统缓存值失败", e);
+                            Log.error("获取系统缓存值失败", e);
                             return null;
                         }
                     });
 
             // 根据查询结果决定返回成功还是失败
             if (!queryResult.isSuccess() || queryResult.getData().isEmpty()) {
-                logger.error("未找到缓存值");
+                Log.error("未找到缓存值");
                 return Result.fail("未找到缓存值");
             }
             return Result.success(queryResult.getData().get(0));
         } catch (Exception e) {
-            logger.error("获取系统缓存值失败", e);
+            Log.error("获取系统缓存值失败", e);
             return Result.fail("获取系统缓存值失败: " + e.getMessage());
         }
     }
@@ -501,7 +502,7 @@ public class DataServices {
                     params);
             if (!insertResult.isSuccess()) {
                 // 如果插入失败,记录错误日志并返回失败结果
-                logger.error("数据库缓存插入失败: {}", insertResult.getError());
+                Log.error("数据库缓存插入失败: {}", insertResult.getError());
                 return Result.fail("数据库缓存插入失败: " + insertResult.getError());
             }
             // 插入成功,返回成功结果
@@ -609,7 +610,7 @@ public class DataServices {
                                     rs.getInt("result_type"));
                         } catch (Exception e) {
                             // 日志记录查询失败信息
-                            logger.error("获取服务[{}]信息失败", serviceCode, e);
+                            Log.error("获取服务[{}]信息失败", serviceCode, e);
                             return null;
                         }
                     },true);
@@ -617,7 +618,7 @@ public class DataServices {
             // 检查查询结果是否成功且不为空
             if (!result.isSuccess() || result.getData().isEmpty()) {
                 // 如果查询失败或结果为空,记录日志并返回失败结果
-                logger.error("未找到服务[{}]配置", serviceCode);
+                Log.error("未找到服务[{}]配置", serviceCode);
                 return Result.fail("未找到服务配置");
             }
 
@@ -625,7 +626,7 @@ public class DataServices {
             return Result.success(result.getData().get(0));
         } catch (Exception e) {
             // 日志记录获取服务信息时的异常
-            logger.error("获取服务信息异常", e);
+            Log.error("获取服务信息异常", e);
             // 返回异常结果
             return Result.fail("获取服务信息异常: " + e.getMessage());
         }
@@ -662,7 +663,7 @@ public class DataServices {
                                     rs.getString("preconditions_param_template"));
                         } catch (Exception e) {
                             // 日志记录查询失败信息
-                            logger.error("获取算法配置失败", e);
+                            Log.error("获取算法配置失败", e);
                             return null;
                         }
                     },true);

+ 43 - 42
src/main/java/com/bfkj/unidia/Core/ServiceController.java

@@ -4,6 +4,7 @@ import com.bfkj.unidia.Result;
 import com.bfkj.unidia.SystemEnvCache;
 import com.bfkj.unidia.DataBaseUtils.DbExecutor;
 import com.bfkj.unidia.IOUtils.HttpHelper;
+import com.bfkj.unidia.logUtils.Log;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -99,7 +100,7 @@ public class ServiceController {
                 return sendRemoteCommand(containerCode, serviceCode, type);
             }
         } catch (Exception e) {// 如果发生异常,返回服务启动失败的信息
-            logger.error("服务启动失败: " + e.getMessage());
+            Log.error("服务启动失败: " + e.getMessage());
             return Result.fail("服务启动失败: " + e.getMessage());
         }
     }
@@ -131,14 +132,14 @@ public class ServiceController {
                 // 如果操作成功,累加成功计数
                 successCount = successCount + controlleredService.getData();
                 // 记录成功日志
-                logger.info((type == 1?"启动":"停止") + "服务成功: " + serviceCode);
+                Log.info((type == 1?"启动":"停止") + "服务成功: " + serviceCode);
             } else {
                 // 如果操作失败,记录错误日志
-                logger.error((type == 1?"启动":"停止") + "服务失败: " + serviceCode + ": " + controlleredService.getError());
+                Log.error((type == 1?"启动":"停止") + "服务失败: " + serviceCode + ": " + controlleredService.getError());
             }
         }
         // 操作完成后,记录总览日志
-        logger.info((type == 1?"启动":"停止") + "服务完成,总计{}服务,成功数量: {}",serviceInfo.getData().size(),successCount);
+        Log.info((type == 1?"启动":"停止") + "服务完成,总计{}服务,成功数量: {}",serviceInfo.getData().size(),successCount);
         // 返回成功计数
         return Result.success(successCount);
     }
@@ -169,14 +170,14 @@ public class ServiceController {
             if(controlleredContainer.isSuccess()) {
                 successCount = successCount + controlleredContainer.getData();
                 // 记录操作日志
-                logger.info((type == 1?"启动":"停止") + serviceCode);
+                Log.info((type == 1?"启动":"停止") + serviceCode);
             } else {
                 // 如果操作失败,记录错误日志
-                logger.error((type == 1?"启动":"停止") + "服务失败: " + serviceCode + ": " + controlleredContainer.getError());
+                Log.error((type == 1?"启动":"停止") + "服务失败: " + serviceCode + ": " + controlleredContainer.getError());
             }
         }
         // 操作完成后,记录总览日志
-        logger.info((type == 1?"启动":"停止") + "服务完成,总计{}服务,成功数量: {}",allContainers.getData().size(),successCount);
+        Log.info((type == 1?"启动":"停止") + "服务完成,总计{}服务,成功数量: {}",allContainers.getData().size(),successCount);
         // 返回成功操作的服务数量
         return Result.success(successCount);
     }
@@ -219,7 +220,7 @@ public class ServiceController {
             }
         } catch (Exception e) {
             // 捕获异常,返回失败结果,包含异常信息
-            logger.error("本地服务{}启动失败: ",serviceCode, e);
+            Log.error("本地服务{}启动失败: ",serviceCode, e);
             return Result.fail("本地服务启动失败: " + e.getMessage());
         }
     }
@@ -413,7 +414,7 @@ public class ServiceController {
                         if (mode != 0) continue;
 
                         String serviceCode = (String) service.get("service_code");
-                        logger.info("单一竞争模式服务处理:{}",serviceCode);
+                        Log.info("单一竞争模式服务处理:{}",serviceCode);
 
                         // 获取服务的心跳时间和服务所在的容器代码
                         LocalDateTime heartbeatTime = (LocalDateTime) service.get("heartbeat_time");
@@ -421,7 +422,7 @@ public class ServiceController {
 
                         // 检查服务是否超时,如果超时则尝试竞争
                         if (heartbeatTime == null || Duration.between(heartbeatTime, LocalDateTime.now()).getSeconds() > 8) {
-                            logger.info("单一竞争模式服务开始竞争:{}",serviceCode);
+                            Log.info("单一竞争模式服务开始竞争:{}",serviceCode);
 
                             // 停止当前容器中的服务
                             stopService(systemEnvCache.get("container_code", String.class),serviceCode);
@@ -429,7 +430,7 @@ public class ServiceController {
                             // 尝试竞争服务,如果成功则启动服务
                             if (Seize(serviceCode,heartbeatTime,heartbeat_container_code)) {
                                 if (!taskRegistry.containsKey(serviceCode)) {
-                                    logger.info("单一竞争模式服务,竞争成功:{}",serviceCode);
+                                    Log.info("单一竞争模式服务,竞争成功:{}",serviceCode);
                                     startService(systemEnvCache.get("container_code", String.class),serviceCode);
                                 }
                             }
@@ -437,7 +438,7 @@ public class ServiceController {
                     }
                 }
             } catch (Exception e) {
-                logger.error("竞争模式处理失败", e);
+                Log.error("竞争模式处理失败", e);
             }
         }, Duration.ofSeconds(6));
     }
@@ -480,7 +481,7 @@ public class ServiceController {
                     && result.getData() > 0;
         } catch (Exception e) {
             // 如果发生异常,记录错误日志并返回false
-            logger.error("竞争失败", e);
+            Log.error("竞争失败", e);
             return false;
         }
     }
@@ -496,13 +497,13 @@ public class ServiceController {
     private synchronized void executeServiceTask(String serviceCode, int operatingMode, int serviceType) {
         try {
             // 调用数据服务处理逻辑
-            logger.info("执行服务任务:{}", serviceCode);
+            Log.info("执行服务任务:{}", serviceCode);
                 if (operatingMode == 0){
                     if (singleContentionHandling(serviceCode, operatingMode, serviceType)){
-                        logger.info("单一竞争成功!");
+                        Log.info("单一竞争成功!");
                         dataServices.process(Map.of("service_code", serviceCode));
                     }else {
-                        logger.info("单一竞争失败!");
+                        Log.info("单一竞争失败!");
                     }
                 }else {
                     // 非单一竞争模式那么,正常执行
@@ -510,7 +511,7 @@ public class ServiceController {
                 }
         } catch (Exception e) {
             // 记录处理服务代码过程中发生的错误
-            logger.error("执行服务任务{}失败",serviceCode, e);
+            Log.error("执行服务任务{}失败",serviceCode, e);
         }
     }
 
@@ -539,14 +540,14 @@ public class ServiceController {
                             return container;
                         }
                         catch (Exception e){
-                            logger.error("获取容器列表失败: " + e.getMessage());
+                            Log.error("获取容器列表失败: " + e.getMessage());
                             return null;// 如果提取失败,返回null表示此条目无效
                         }
                     });
             // 根据查询结果的成功与否,决定返回成功结果还是失败结果
             return result.isSuccess() ? result : Result.fail("获取容器列表失败", result.getMetrics());
         } catch (Exception e) {// 如果在执行过程中捕获到异常,返回失败结果,并包含异常信息
-            logger.error("获取容器列表失败: " + e.getMessage());
+            Log.error("获取容器列表失败: " + e.getMessage());
             return Result.fail("获取容器列表失败: " + e.getMessage());
         }
     }
@@ -584,14 +585,14 @@ public class ServiceController {
                             return serviceList;
                         }
                         catch (Exception e){
-                            logger.error("获取容器列表失败: " + e.getMessage());
+                            Log.error("获取容器列表失败: " + e.getMessage());
                             return null;// 如果提取失败,返回null表示此条目无效
                         }
                     });
             // 根据查询结果,返回成功或失败的Result对象
             return result.isSuccess() ? result : Result.fail("获取服务信息失败", result.getMetrics());
         } catch (Exception e) {// 如果在获取服务信息的过程中发生异常,返回失败的Result对象,并包含异常信息
-            logger.error("获取服务信息失败: " + e.getMessage());
+            Log.error("获取服务信息失败: " + e.getMessage());
             return Result.fail("获取服务信息失败: " + e.getMessage());
         }
     }
@@ -643,27 +644,27 @@ public class ServiceController {
 //        使用update service_info set last_container_code = 当前容器编号,last_time = 当前时间
 // where 服务代码 = serviceCode and last_container_code = 最后活跃容器编号 and last_time = 查询出的最后活跃时间
             List<Map<String, ?>> conditions = null;
-            Map<String, Object> conditionsMap =  null;
-            if (lastContainerCode==null){
-                HashMap<String, Object> map = new HashMap<>();
-                map.put("left", "(");
-                map.put("value", null);
-                map.put("column", "last_container_code");
-                map.put("comparison", "IS NULL");
-                map.put("connection", " AND");
-                map.put("right", "");
-                conditions =List.of(
-                        map,
-                        Map.of(
-                                "left", "",
-                                "column", "service_code",
-                                "comparison", "=",
-                                "value", serviceCode,
-                                "connection", "AND",
-                                "right", ")"
-                        )
-                );
-            }else {
+        Map<String, Object> conditionsMap =  null;
+        if (lastContainerCode==null){
+            HashMap<String, Object> map = new HashMap<>();
+            map.put("left", "(");
+            map.put("value", null);
+            map.put("column", "last_container_code");
+            map.put("comparison", "IS NULL");
+            map.put("connection", " AND");
+            map.put("right", "");
+            conditions =List.of(
+                    map,
+                    Map.of(
+                            "left", "",
+                            "column", "service_code",
+                            "comparison", "=",
+                            "value", serviceCode,
+                            "connection", "AND",
+                            "right", ")"
+                    )
+            );
+        }else {
                 conditionsMap = Map.of(
                         "last_time", last_time,
                         "last_container_code", lastContainerCode,

+ 9 - 8
src/main/java/com/bfkj/unidia/DataBaseUtils/ConnectionPoolManager.java

@@ -3,6 +3,7 @@ package com.bfkj.unidia.DataBaseUtils;
 import com.bfkj.unidia.DataUtils.DataEncryptionUtil;
 import com.bfkj.unidia.Result;
 import com.bfkj.unidia.SystemEnvCache;
+import com.bfkj.unidia.logUtils.Log;
 import com.github.benmanes.caffeine.cache.Cache;
 import com.github.benmanes.caffeine.cache.Caffeine;
 import com.zaxxer.hikari.HikariConfig;
@@ -98,7 +99,7 @@ public class ConnectionPoolManager {
             }
         } catch (Exception e) {
             // 全局异常捕获:记录错误日志并返回失败结果
-            logger.error("获取数据源失败", e);
+            Log.error("获取数据源失败", e);
             return Result.fail("获取数据源失败: ",e);
         }
     }
@@ -136,7 +137,7 @@ public class ConnectionPoolManager {
             // 返回初始化后的数据源实例
             return Result.success(new HikariDataSource(config));
         } catch (Exception e) {
-            logger.error("创建数据源失败: {}", dbKey + e.getMessage(),e);
+            Log.error("创建数据源失败: {}", dbKey + e.getMessage(),e);
             return Result.fail("创建数据源" + dbKey + "失败: " ,e);
         }
     }
@@ -178,7 +179,7 @@ public class ConnectionPoolManager {
             return encryptedPassword;
         } catch (Exception e) {
             // 记录解密失败日志
-            logger.error("数据库密码解密失败", e);
+            Log.error("数据库密码解密失败", e);
             return encryptedPassword;
         }
     }
@@ -308,7 +309,7 @@ public class ConnectionPoolManager {
             }
         } catch (Exception e) {
             // 全局异常捕获:记录错误日志并返回失败结果
-            logger.error("获取JdbcTemplate失败", e);
+            Log.error("获取JdbcTemplate失败", e);
             return Result.fail("获取JdbcTemplate失败: ",e);
         }
     }
@@ -320,7 +321,7 @@ public class ConnectionPoolManager {
             }
             return Result.success(new JdbcTemplate(dataSourceResult.getData()));
         }catch (Exception e){
-            logger.error("获取JdbcTemplate失败", e);
+            Log.error("获取JdbcTemplate失败", e);
             return Result.fail(e.getMessage());
         }
     }
@@ -340,15 +341,15 @@ public class ConnectionPoolManager {
                 ds.close();
             }
         } catch (Exception e) {
-            logger.error("关闭数据源失败: {}", key, e);
+            Log.error("关闭数据源失败: {}", key, e);
         }
     }
     //销毁前停止心跳
     @PreDestroy
     public void destroy() {
         dataSourceCache.invalidateAll();
-        logger.info("数据源缓存清除");
+        Log.info("数据源缓存清除");
         jdbcTemplateCache.invalidateAll();
-        logger.info("JdbcTemplate缓存清除");
+        Log.info("JdbcTemplate缓存清除");
     }
 }

+ 9 - 8
src/main/java/com/bfkj/unidia/DataBaseUtils/DbExecutor.java

@@ -1,6 +1,7 @@
 package com.bfkj.unidia.DataBaseUtils;
 
 import com.bfkj.unidia.Result;
+import com.bfkj.unidia.logUtils.Log;
 import com.github.benmanes.caffeine.cache.Cache;
 import com.github.benmanes.caffeine.cache.Caffeine;
 import org.slf4j.Logger;
@@ -142,7 +143,7 @@ public class DbExecutor {
             // 返回插入操作的结果,包括受影响的行数
             return Result.success(null);
         } catch (Exception e) {
-            logger.error("新增错误", e);
+            Log.error("新增错误", e);
             return Result.fail("新增错误", e);
         }
     }
@@ -179,7 +180,7 @@ public class DbExecutor {
             return Result.success(failedList);
         } catch (Exception e) {
             // 记录错误日志
-            logger.error("动态更新失败", e);
+            Log.error("动态更新失败", e);
             // 返回更新失败的Result对象,包含异常信息
             return Result.fail("动态更新失败: " + e.getMessage());
         }
@@ -232,7 +233,7 @@ public class DbExecutor {
             // 返回插入操作的结果,包括受影响的行数
             return Result.success(insertCount);
         } catch (Exception e) {
-            logger.error("新增错误", e);
+            Log.error("新增错误", e);
             return Result.fail("新增错误", e);
         }
     }
@@ -269,7 +270,7 @@ public class DbExecutor {
             return Result.success(updateCount);
         } catch (Exception e) {
             // 记录错误日志
-            logger.error("动态更新失败", e);
+            Log.error("动态更新失败", e);
             // 返回更新失败的Result对象,包含异常信息
             return Result.fail("动态更新失败: " + e.getMessage());
         }
@@ -295,7 +296,7 @@ public class DbExecutor {
             return jdbcExecutor.update(dbConfig, whereString.toString(), whereParam);
         } catch (Exception e) {
             // 记录错误日志
-            logger.error("动态删除失败", e);
+            Log.error("动态删除失败", e);
             // 返回删除失败的结果
             return Result.fail("动态删除失败: " + e.getMessage());
         }
@@ -422,7 +423,7 @@ public class DbExecutor {
 
             return jdbcExecutor.query(dbConfig, whereString.toString(), whereParam, page, pageSize, rowMapper);
         } catch (Exception e) {
-            logger.error("动态查询失败", e);
+            Log.error("动态查询失败", e);
             return Result.fail("动态查询失败: " + e.getMessage());
         }
     }
@@ -452,7 +453,7 @@ public class DbExecutor {
             consolidateConditional(dbParams, whereString, whereParam);
             return jdbcExecutor.queryForList(dbConfig, whereString.toString(), whereParam, page, pageSize);
         } catch (Exception e) {
-            logger.error("动态查询失败", e);
+            Log.error("动态查询失败", e);
             return Result.fail("动态查询失败: " + e.getMessage());
         }
     }
@@ -498,7 +499,7 @@ public class DbExecutor {
             }
             return result;
         } catch (Exception e) {
-            logger.error("缓存查询失败", e);
+            Log.error("缓存查询失败", e);
             return Result.fail("缓存查询失败: " + e.getMessage());
         }
     }

+ 0 - 2
src/main/java/com/bfkj/unidia/DataBaseUtils/DbParamsService.java

@@ -2,10 +2,8 @@ package com.bfkj.unidia.DataBaseUtils;
 
 import com.bfkj.unidia.Result;
 import com.github.benmanes.caffeine.cache.Cache;
-import com.github.benmanes.caffeine.cache.Caffeine;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Service;
 
 import java.time.Instant;

+ 2 - 1
src/main/java/com/bfkj/unidia/DataBaseUtils/DbUtils.java

@@ -1,6 +1,7 @@
 package com.bfkj.unidia.DataBaseUtils;
 
 import com.bfkj.unidia.Result;
+import com.bfkj.unidia.logUtils.Log;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
@@ -55,7 +56,7 @@ public class DbUtils {
             }
             return Result.success(Map.of("dbKey",url + "|" + dbConfig.get("username"),  "dbType",dbType));
         } catch (Exception e) {
-            logger.error("验证数据库连接失败", e);
+            Log.error("验证数据库连接失败", e);
             return Result.fail("验证数据库连接失败: " + e.getMessage());
         }
     }

+ 9 - 11
src/main/java/com/bfkj/unidia/DataBaseUtils/JdbcExecutor.java

@@ -1,6 +1,7 @@
 package com.bfkj.unidia.DataBaseUtils;
 
 import com.bfkj.unidia.Result;
+import com.bfkj.unidia.logUtils.Log;
 import com.github.benmanes.caffeine.cache.Cache;
 import com.github.benmanes.caffeine.cache.Caffeine;
 import com.zaxxer.hikari.HikariDataSource;
@@ -19,9 +20,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
-import org.springframework.jdbc.core.namedparam.SqlParameterSource;
-import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Service;
 
 import java.sql.*;
@@ -106,7 +104,7 @@ public class JdbcExecutor {
                             ps.setObject(i + 1, params.get(i)); // 参数从 1 开始
                         }
                     }
-                    logger.info("ps.toString():{}", ps.toString());
+                    Log.info("ps.toString():{}", ps.toString());
                     // 执行查询
                     ResultSet rs = ps.executeQuery();
                     // 映射结果
@@ -119,7 +117,7 @@ public class JdbcExecutor {
                     return Result.fail("查询失败: " + e.getMessage());
                 }
             } catch (Exception e) {
-                logger.error("查询失败:{}; SQL: {}, params: {}", e.getMessage(), paginatedSql, params);
+                Log.error("查询失败:{}; SQL: {}, params: {}", e.getMessage(), paginatedSql, params);
                 return Result.fail(e.getMessage());
             }
         });
@@ -163,7 +161,7 @@ public class JdbcExecutor {
                 List<Map<String, Object>> queryForList = jdbcTemplate.queryForList(paginatedSql, test);
                 return Result.success(queryForList);
             }catch (Exception e){
-                logger.error("查询失败:{};SQL:{},params:{}", e.getMessage(),  paginatedSql, params);
+                Log.error("查询失败:{};SQL:{},params:{}", e.getMessage(),  paginatedSql, params);
                 return Result.fail(e.getMessage());
             }
         });
@@ -183,7 +181,7 @@ public class JdbcExecutor {
             try {
                 return Result.success(jdbcTemplate.queryForMap(sql, params));
             }catch (Exception e){
-                logger.error("查询失败:{};SQL:{},params:{}", e.getMessage(),  sql, params);
+                Log.error("查询失败:{};SQL:{},params:{}", e.getMessage(),  sql, params);
                 return Result.fail(e.getMessage());
             }
         });
@@ -206,7 +204,7 @@ public class JdbcExecutor {
                 Object queriedForObject = jdbcTemplate.queryForObject(sql, Object.class, params.toArray());
                 return Result.success(queriedForObject);
             }catch (Exception e){
-                logger.error("查询失败:{};SQL:{},params:{}", e.getMessage(),  sql, params);
+                Log.error("查询失败:{};SQL:{},params:{}", e.getMessage(),  sql, params);
                 return Result.fail(e.getMessage());
             }
         });
@@ -324,12 +322,12 @@ public class JdbcExecutor {
                     } catch (SQLException ex) {
                         logger.warn("回滚事务失败", ex);
                     }
-                    logger.error("更新失败:{};SQL:{},params:{}", e.getMessage(),  sql, params);
+                    Log.error("更新失败:{};SQL:{},params:{}", e.getMessage(),  sql, params);
                     // 返回失败结果
                     return Result.fail("更新失败: " + e.getMessage());
                 }
             }catch (Exception e){
-                logger.error("获取数据库连接失败:{}", e.getMessage());
+                Log.error("获取数据库连接失败:{}", e.getMessage());
                 return Result.fail("获取数据库连接失败: " + e.getMessage());
             }
         });
@@ -523,7 +521,7 @@ public class JdbcExecutor {
                 return Result.fail("批量插入失败: " + e.getMessage());
             }
         }catch (Exception e){
-            logger.error("获取数据库连接失败:{}", e.getMessage());
+            Log.error("获取数据库连接失败:{}", e.getMessage());
             return Result.fail("获取数据库连接失败: " + e.getMessage());
         }
     }

+ 9 - 8
src/main/java/com/bfkj/unidia/DataBaseUtils/TableStructureManager.java

@@ -1,6 +1,7 @@
 package com.bfkj.unidia.DataBaseUtils;
 
 import com.bfkj.unidia.Result;
+import com.bfkj.unidia.logUtils.Log;
 import com.github.benmanes.caffeine.cache.Cache;
 import com.github.benmanes.caffeine.cache.Caffeine;
 import com.zaxxer.hikari.HikariDataSource;
@@ -124,7 +125,7 @@ public class TableStructureManager {
                 return result;
             }
         } catch (Exception e) {
-            logger.error("获取表结构失败,dbKey: {}, tableName: {}", dbKey, tableName, e);
+            Log.error("获取表结构失败,dbKey: {}, tableName: {}", dbKey, tableName, e);
             return Result.fail("获取表结构失败: 系统错误");
         }
     }
@@ -156,12 +157,12 @@ public class TableStructureManager {
                 return Result.success(new TableSchema(tableName, columnMap));
             } catch (SQLException e) {
                 // 记录详细日志(示例)
-                logger.error("获取表结构失败: {}", e.getMessage(), e);
+                Log.error("获取表结构失败: {}", e.getMessage(), e);
                 return Result.fail("获取表结构失败: ", e);
             }
         } catch (Exception e) {
             // 记录非 SQL 异常日志(示例)
-            logger.error("非预期异常: {}", e.getMessage(), e);
+            Log.error("非预期异常: {}", e.getMessage(), e);
             return Result.fail("获取表结构失败: ", e);
         }
     }
@@ -232,7 +233,7 @@ public class TableStructureManager {
             }
         } catch (SQLException e) {
             // 建议记录日志,避免静默失败
-            logger.info("Failed to get schema: " + e.getMessage());
+            Log.info("Failed to get schema: " + e.getMessage());
             return null;
         }
     }
@@ -289,7 +290,7 @@ public class TableStructureManager {
 
             return result;
         } catch (Exception e) {
-            logger.error("创建表失败", e);
+            Log.error("创建表失败", e);
             return Result.fail("创建表失败: " + e.getMessage());
         } finally {
             lock.unlock();
@@ -396,7 +397,7 @@ public class TableStructureManager {
 
             return Result.success(totalAffectedRows);
         } catch (Exception e) {
-            logger.error("添加字段失败", e);
+            Log.error("添加字段失败", e);
             return Result.fail("添加字段失败: " + e.getMessage());
         }finally {
             lock.unlock();
@@ -460,7 +461,7 @@ public class TableStructureManager {
         for (String sql : alterStatements) {
             Result<Integer> result = jdbcExecutor.executeDDL(dbConfig, sql);
             if (!result.isSuccess()) {
-                logger.error("执行DDL失败: " + result.getError());
+                Log.error("执行DDL失败: " + result.getError());
                 //return Result.fail(result.getError()).getData(); // 返回错误结果
                 continue;
             }
@@ -491,7 +492,7 @@ public class TableStructureManager {
                 }
             }
         } catch (Exception e) {
-            logger.error("清除表结构失败", e);
+            Log.error("清除表结构失败", e);
         }
     }
     /**

+ 5 - 4
src/main/java/com/bfkj/unidia/DataUtils/DataFormatConverter.java

@@ -1,5 +1,6 @@
 package com.bfkj.unidia.DataUtils;
 
+import com.bfkj.unidia.logUtils.Log;
 import com.fasterxml.jackson.core.JsonFactory;
 import com.fasterxml.jackson.core.JsonGenerator;
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -74,7 +75,7 @@ public class DataFormatConverter {
         try (StringReader reader = new StringReader(xml)) {
             return xmlToMap(reader);
         }catch (XMLStreamException e){
-            logger.error("XML 转 Map 失败", e);
+            Log.error("XML 转 Map 失败", e);
             return null;
         }
     }
@@ -83,7 +84,7 @@ public class DataFormatConverter {
         try {
             return parse(eventReader);
         }catch (XMLStreamException e){
-            logger.error("XML 转 Map 失败", e);
+            Log.error("XML 转 Map 失败", e);
             return null;
         }finally {
             eventReader.close();
@@ -97,7 +98,7 @@ public class DataFormatConverter {
             eventReader = xmlInputFactory.get().createXMLEventReader(xmlReader);
             return parse(eventReader);
         } catch (XMLStreamException e) {
-            logger.error("XML 转 Map 失败", e);
+            Log.error("XML 转 Map 失败", e);
             return null;
         }finally {
             if (eventReader != null) {
@@ -129,7 +130,7 @@ public class DataFormatConverter {
                     Attribute attr = attributes.next();
                     String attrQName = attr.getName().getLocalPart();
                     if (mapStack.isEmpty()) {
-                        logger.error("无效XML结构:属性未关联到元素");
+                        Log.error("无效XML结构:属性未关联到元素");
                         continue;
                     }
                     mapStack.peek().put("@" + attrQName, attr.getValue());

+ 23 - 22
src/main/java/com/bfkj/unidia/DataUtils/ScriptExecutor.java

@@ -1,6 +1,7 @@
 package com.bfkj.unidia.DataUtils;
 
 import com.bfkj.unidia.Result;
+import com.bfkj.unidia.logUtils.Log;
 import com.github.benmanes.caffeine.cache.Cache;
 import com.github.benmanes.caffeine.cache.Caffeine;
 import org.graalvm.polyglot.*;
@@ -88,12 +89,12 @@ public class ScriptExecutor {
             Value resultValue = executeScript(context, script, scriptKey);// 执行JavaScript脚本并获取原始结果值
             Object resultData = convertResult(resultValue);// 将JS结果值转换为Java对象
             if (resultData instanceof String){
-                logger.info("js方法执行:");
-                logger.info(String.valueOf(resultData));
+                Log.info("js方法执行:");
+                Log.info(String.valueOf(resultData));
             }
             return Result.success(resultData, buildMetrics(startTime, script,params != null ? params.size() : 0));
         } catch (Exception e) {
-            logger.error("JS执行异常: {}, 脚本: {}", e.getMessage(), script, e);
+            Log.error("JS执行异常: {}, 脚本: {}", e.getMessage(), script, e);
             return Result.fail(e.getMessage(), buildMetrics(startTime, script, e));
         }
     }
@@ -140,7 +141,7 @@ public class ScriptExecutor {
             try {
                 return Source.newBuilder(ENGINE_TYPE, script, DEFAULT_SCRIPT_NAME).build();
             } catch (IOException e) {
-                logger.error("JS脚本构建异常: {}", e.getMessage(), e);
+                Log.error("JS脚本构建异常: {}", e.getMessage(), e);
                 throw new RuntimeException("JS脚本构建失败", e);
             }
         });
@@ -257,7 +258,7 @@ public class ScriptExecutor {
             }
             return invokeInstanceMethod(startTime,className,instance, methodName, paramTypes,params);
         } catch (Exception e) {
-            logger.error("Java方法执行异常: {}, 类: {}.{}", e.getMessage(), className + methodName, methodName, e);
+            Log.error("Java方法执行异常: {}, 类: {}.{}", e.getMessage(), className + methodName, methodName, e);
             return Result.fail(e.getMessage(), buildMetrics(startTime, className + methodName, e));
         }
     }
@@ -297,7 +298,7 @@ public class ScriptExecutor {
                         try {// 最终尝试Class.forName
                             return Class.forName(className);
                         } catch (ClassNotFoundException ey) {
-                            logger.error("类加载失败: {}", className, ey);
+                            Log.error("类加载失败: {}", className, ey);
                             return null;
                         }
                     }
@@ -502,7 +503,7 @@ public class ScriptExecutor {
                 constructor.setAccessible(true);//设置构造方法可访问(突破private/protected限制)
                 return constructor.newInstance();//通过反射创建新实例
             } catch (Exception e) {
-                logger.error("创建实例失败", e);
+                Log.error("创建实例失败", e);
                 return null;
             }
         });
@@ -613,13 +614,13 @@ public class ScriptExecutor {
             try {
                 return Integer.parseInt(strValue);
             }catch (Exception e){
-                logger.error("value");
-                logger.error(String.valueOf(value));
-                logger.error("strValue");
-                logger.error(strValue);
-                logger.error("targetType",targetType);
-                logger.error(String.valueOf(targetType));
-                logger.error("转换Integer失败",e);
+                Log.error("value");
+                Log.error(String.valueOf(value));
+                Log.error("strValue");
+                Log.error(strValue);
+                Log.error("targetType",targetType);
+                Log.error(String.valueOf(targetType));
+                Log.error("转换Integer失败",e);
                 return null;
             }
         }
@@ -631,7 +632,7 @@ public class ScriptExecutor {
             return value;
         }
 
-        logger.error("无法转换类型 " + value.getClass() +
+        Log.error("无法转换类型 " + value.getClass() +
                 " 到目标类型 " + targetType.getName());
         return null;
     }
@@ -646,7 +647,7 @@ public class ScriptExecutor {
     @SuppressWarnings("unchecked")
     private <T extends Enum<T>> T convertToEnum(Class<Enum<?>> enumClass, String enumStr) {
         if (!enumClass.isEnum()) {
-            logger.error("目标类型必须是枚举类型");
+            Log.error("目标类型必须是枚举类型");
         }
         return Enum.valueOf((Class<T>) enumClass, enumStr);
     }
@@ -699,14 +700,14 @@ public class ScriptExecutor {
                             Object convertedValue = convertType(setter.getParameterTypes()[0], value);
                             setter.invoke(bean, convertedValue);
                         } catch (IllegalAccessException | InvocationTargetException e) {
-                            logger.error("设置属性失败: " + strKey, e);
+                            Log.error("设置属性失败: " + strKey, e);
                         }
                     }
                 }
             });
             return bean;
         } catch (Exception e) {
-            logger.error("Map转Bean失败: " + targetType.getName(), e);
+            Log.error("Map转Bean失败: " + targetType.getName(), e);
             return null;
         }
     }
@@ -794,7 +795,7 @@ public class ScriptExecutor {
             Value resultValue = handler.execute(context, script);
             return Result.success(convertResult(resultValue), buildMetrics(startTime, script, params));
         } catch (Exception e) {
-            logger.error("脚本执行异常: {}, 语言: {}", e.getMessage(), language, e);
+            Log.error("脚本执行异常: {}, 语言: {}", e.getMessage(), language, e);
             return Result.fail(e.getMessage(), buildMetrics(startTime, script, e));
         }
     }
@@ -815,9 +816,9 @@ public class ScriptExecutor {
         if (value instanceof AutoCloseable closeable) {
             try {
                 closeable.close(); // 自动关闭资源
-                logger.info("自动关闭{}缓存: {}", cacheType,key);
+                Log.info("自动关闭{}缓存: {}", cacheType,key);
             } catch (Exception e) {
-                logger.error("关闭{}缓存失败", cacheType,e);
+                Log.error("关闭{}缓存失败", cacheType,e);
             }
         }
     }
@@ -826,7 +827,7 @@ public class ScriptExecutor {
      */
     @PreDestroy
     private void cleanup() {
-        logger.info("开始清理反射实例缓存");
+        Log.info("开始清理反射实例缓存");
         scriptCache.asMap().forEach((cls, instance) -> closeAutoCloseable(instance,cls,"JS脚本缓存"));
         classCache.asMap().forEach((cls, instance) -> closeAutoCloseable(instance,cls,"类缓存"));
         methodCache.asMap().forEach((cls, instance) -> closeAutoCloseable(instance,cls,"方法缓存"));

+ 11 - 10
src/main/java/com/bfkj/unidia/IOUtils/ActiveMQHelper.java

@@ -2,6 +2,7 @@ package com.bfkj.unidia.IOUtils;
 
 import com.bfkj.unidia.DataUtils.DataFormatConverter;
 import com.bfkj.unidia.Result;
+import com.bfkj.unidia.logUtils.Log;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -89,7 +90,7 @@ public class ActiveMQHelper {
                     TextMessage textMessage = session.createTextMessage(message);//创建文本消息
                     producer.send(textMessage);//发送消息
                 } catch (JMSException e) {
-                    logger.error("发送消息失败: {}", message, e);
+                    Log.error("发送消息失败: {}", message, e);
                     failList.add(message);
                 }
             }
@@ -100,7 +101,7 @@ public class ActiveMQHelper {
             return Result.success(failList);
         } catch (Exception e) {
             rollback(session,"ActiveMQHelper的batchSendMessage回滚事务失败");
-            logger.error("ActiveMQ 批量发送异常", e);
+            Log.error("ActiveMQ 批量发送异常", e);
             return Result.fail("ActiveMQ 批量发送异常: " + e.getMessage());
         }
     }
@@ -150,7 +151,7 @@ public class ActiveMQHelper {
                         logger.warn("不支持的消息类型: {}", message.getJMSMessageID());
                     }
                 } catch (JMSException e) {
-                    logger.error("接收消息失败", e);
+                    Log.error("接收消息失败", e);
                     break;
                 }
             }
@@ -161,7 +162,7 @@ public class ActiveMQHelper {
             return Result.success(receivedMessages);
         } catch (Exception e) {// 异常情况下尝试回滚事务
             rollback(session,"ActiveMQHelper的receiveMessage回滚事务失败");
-            logger.error("ActiveMQ 批量消费异常", e);
+            Log.error("ActiveMQ 批量消费异常", e);
             return Result.fail("批量消费异常: " + e.getMessage());
         }
     }
@@ -207,7 +208,7 @@ public class ActiveMQHelper {
                 return factory;
             } catch (Exception e) {
                 // 记录连接工厂创建失败的异常信息
-                logger.error("创建连接工厂失败", e);
+                Log.error("创建连接工厂失败", e);
                 return null;
             }
         }
@@ -293,7 +294,7 @@ public class ActiveMQHelper {
                 return newSession;
             } catch (JMSException e) {
                 // 记录会话创建失败日志
-                logger.error("创建会话失败", e);
+                Log.error("创建会话失败", e);
                 return null;
             }
         }
@@ -329,7 +330,7 @@ public class ActiveMQHelper {
                 return newProducer;
             } catch (JMSException e) {
                 // 记录生产者创建失败的异常日志
-                logger.error("创建生产者失败", e);
+                Log.error("创建生产者失败", e);
                 return null;
             }
         }
@@ -363,7 +364,7 @@ public class ActiveMQHelper {
                 return newConsumer;
             } catch (JMSException e) {
                 // 记录消费者创建失败的错误信息
-                logger.error("创建消费者失败", e);
+                Log.error("创建消费者失败", e);
                 return null;
             }
         }
@@ -489,9 +490,9 @@ public class ActiveMQHelper {
         if (value instanceof AutoCloseable closeable) {
             try {
                 closeable.close();
-                logger.info("自动关闭{}缓存: {}", "缓存资源", key);
+                Log.info("自动关闭{}缓存: {}", "缓存资源", key);
             } catch (Exception e) {
-                logger.error("关闭{}缓存失败", "缓存资源", e);
+                Log.error("关闭{}缓存失败", "缓存资源", e);
             }
         }
     }

+ 2 - 1
src/main/java/com/bfkj/unidia/IOUtils/HttpHelper.java

@@ -1,6 +1,7 @@
 package com.bfkj.unidia.IOUtils;
 
 import com.bfkj.unidia.Result;
+import com.bfkj.unidia.logUtils.Log;
 import org.apache.hc.client5.http.classic.methods.*;
 import org.apache.hc.client5.http.config.RequestConfig;
 import org.apache.hc.client5.http.entity.mime.FileBody;
@@ -83,7 +84,7 @@ public class HttpHelper {
         try (ClassicHttpResponse response = httpClient.executeOpen(host,request, context)) {
             return Result.success(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8)) ;
         }catch (Exception e){
-            logger.error("HTTP请求异常", e);
+            Log.error("HTTP请求异常", e);
             return Result.fail("HTTP请求异常: " + e.getMessage());
         }
     }

+ 35 - 34
src/main/java/com/bfkj/unidia/IOUtils/IBMMQHelper.java

@@ -2,6 +2,7 @@ package com.bfkj.unidia.IOUtils;
 
 import com.bfkj.unidia.DataUtils.DataFormatConverter;
 import com.bfkj.unidia.Result;
+import com.bfkj.unidia.logUtils.Log;
 import com.github.benmanes.caffeine.cache.Cache;
 import com.ibm.mq.*;
 import com.ibm.mq.constants.CMQC;
@@ -64,11 +65,11 @@ public class IBMMQHelper {
         try {
             Result<String> validateResult = validateConfig(mqConfig, queueName, messageList);
             if (!validateResult.isSuccess()) {
-                logger.error("MQ配置验证失败: {}", validateResult.getError());
+                Log.error("MQ配置验证失败: {}", validateResult.getError());
                 return Result.fail(validateResult.getError());
             }
             cacheKey = validateResult.getData();
-            logger.info("IBMMQ发送,参数检测通过……");
+            Log.info("IBMMQ发送,参数检测通过……");
             queueManager = getQueueManager(mqConfig,cacheKey);
             if (queueManager == null) {
                 return Result.fail("获取IBMMQ队列管理器失败");
@@ -76,7 +77,7 @@ public class IBMMQHelper {
             MQQueue queue = null;
             try {
                 queue = getproducerMQQueue(queueManager,cacheKey,queueName);
-                logger.info("IBMMQ发送,生产者获取成功,准备发送……");
+                Log.info("IBMMQ发送,生产者获取成功,准备发送……");
                 for (Object messageItem : messageList) {
                     String msg = sendSingleMessage(queue,mqConfig, DataFormatConverter.convertObjectToString(messageItem));
                     if(msg != null){
@@ -88,7 +89,7 @@ public class IBMMQHelper {
                 return Result.fail("IBM MQ 获取生产者队列失败: " + e.getMessage());
             }
         } catch (Exception e) {
-            logger.error("IBM MQ 发送异常", e);
+            Log.error("IBM MQ 发送异常", e);
             closeQueueManager(cacheKey,queueManager);
             return Result.fail("IBM MQ 发送异常: " + e.getMessage());
         }
@@ -133,7 +134,7 @@ public class IBMMQHelper {
             return null;
         } catch (Exception e) {
             // 记录异常日志并返回失败结果
-            logger.error("发送 IBM MQ 消息失败", e);
+            Log.error("发送 IBM MQ 消息失败", e);
 //            return Result.fail("发送消息失败: " + e.getMessage());
             return message;
         }
@@ -165,8 +166,8 @@ public class IBMMQHelper {
     public static Result<List<String>> receiveMessage(Map<String, String> mqConfig,
                                                       String queueName,
                                                       Integer maxMessages) {
-        logger.info("IBM MQ配置-------------------------------------------");
-        logger.info(DataFormatConverter.mapToJson(mqConfig));
+        Log.info("IBM MQ配置-------------------------------------------");
+        Log.info(DataFormatConverter.mapToJson(mqConfig));
         MQQueueManager queueManager = null;
         String cacheKey = null;
         try {
@@ -211,7 +212,7 @@ public class IBMMQHelper {
                             byte[] buffer = new byte[message.getMessageLength()];
                             message.readFully(buffer);
                             String read =  new String(buffer);
-                            logger.info("接收 IBM MQ 队列消息:{}", read);
+                            Log.info("接收 IBM MQ 队列消息:{}", read);
                             messages.add(read);
                         } catch (MQException e) {
                             if (e.getReason() == MQConstants.MQRC_NO_MSG_AVAILABLE) {
@@ -221,28 +222,28 @@ public class IBMMQHelper {
                         }
                     } catch (MQException e) {
                         if (e.reasonCode == MQConstants.MQRC_NO_MSG_AVAILABLE) {
-                            logger.info("IBMMQ没有更多消息");
+                            Log.info("IBMMQ没有更多消息");
                             break; // 没有更多消息,提前结束
                         } else {
-                            logger.error("接收 IBM MQ 消息失败", e);
+                            Log.error("接收 IBM MQ 消息失败", e);
                             return Result.fail("接收消息失败: " + e.getMessage());
                         }
                     }
                 }
                 Result<List<String>> listResult = Result.success(messages);
-                logger.info("最大接收数量:"+maxMessages);
-                logger.info("队列名称:"+queueName);
+                Log.info("最大接收数量:"+maxMessages);
+                Log.info("队列名称:"+queueName);
                 if (Objects.nonNull(listResult.getData())&&listResult.getData().size()>0){
-                    logger.info("发送数量",listResult.getData().size());
+                    Log.info("发送数量",listResult.getData().size());
                 }
                 return listResult;
             } catch (Exception e) {
                 closeQueue(cacheKey, queue, consumerQueueCache);
-                logger.error("IBM MQ 接收异常", e);
+                Log.error("IBM MQ 接收异常", e);
                 return Result.fail("IBM MQ 收异常: " + e.getMessage());
             }
         } catch (Exception e) {
-            logger.error("IBM MQ 接收异常", e);
+            Log.error("IBM MQ 接收异常", e);
             closeQueueManager(cacheKey,queueManager);
             return Result.fail("IBM MQ 接收异常: " + e.getMessage());
         }
@@ -268,15 +269,15 @@ public class IBMMQHelper {
             try {
                 //绑定队列
                 queue = getconsumerMQQueue(queueManager, cacheKey, queueName);
-                logger.info("*************************绑定队列深度");
-                logger.info("队列深度:"+queue);
+                Log.info("*************************绑定队列深度");
+                Log.info("队列深度:"+queue);
                 if(queue == null){
                     return Result.fail("绑定队列失败");
                 }
                 //获取当前队列深度
                 int currentDepth = queue.getCurrentDepth();
-                logger.info("获取队列深度");
-                logger.info("队列深度:"+currentDepth);
+                Log.info("获取队列深度");
+                Log.info("队列深度:"+currentDepth);
                 if (currentDepth == 0) {//队列深度为0,返回空结果
                     return Result.success(new ArrayList<>());
                 }
@@ -300,7 +301,7 @@ public class IBMMQHelper {
                         if (e.reasonCode == MQConstants.MQRC_NO_MSG_AVAILABLE) {
                             break; // 没有更多消息,提前结束
                         } else {
-                            logger.error("接收 IBM MQ 消息失败", e);
+                            Log.error("接收 IBM MQ 消息失败", e);
                             return Result.fail("接收消息失败: " + e.getMessage());
                         }
                     }
@@ -311,15 +312,15 @@ public class IBMMQHelper {
                 if (e.reasonCode == MQConstants.MQRC_NO_MSG_AVAILABLE) {
                     return Result.fail("没有可用消息");
                 }
-                logger.error("接收 IBM MQ 消息失败", e);
+                Log.error("接收 IBM MQ 消息失败", e);
                 return Result.fail("接收消息失败: " + e.getMessage());
             } catch (Exception e) {
                 closeQueue(cacheKey, queue, consumerQueueCache);
-                logger.error("IBM MQ 接收异常", e);
+                Log.error("IBM MQ 接收异常", e);
                 return Result.fail("IBM MQ 收异常: " + e.getMessage());
             }
         } catch (Exception e) {
-            logger.error("IBM MQ 接收异常", e);
+            Log.error("IBM MQ 接收异常", e);
             closeQueueManager(cacheKey,queueManager);
             return Result.fail("IBM MQ 接收异常: " + e.getMessage());
         }
@@ -348,10 +349,10 @@ public class IBMMQHelper {
         if (queueManager != null && queueManager.isConnected()) {
             return queueManager;
         }
-        logger.info("********************获取或创建 IBM MQ 队列管理器实例");
+        Log.info("********************获取或创建 IBM MQ 队列管理器实例");
         if (!Objects.nonNull(mqConfig)){
-            if (Objects.nonNull(mqConfig.get("host"))) logger.info("host:"+mqConfig.get("host"));
-            if (Objects.nonNull(mqConfig.get("port"))) logger.info("端口:"+mqConfig.get("port"));
+            if (Objects.nonNull(mqConfig.get("host"))) Log.info("host:"+mqConfig.get("host"));
+            if (Objects.nonNull(mqConfig.get("port"))) Log.info("端口:"+mqConfig.get("port"));
         }
 
 
@@ -381,11 +382,11 @@ public class IBMMQHelper {
 ps -ef
                 // 将新创建的实例存入缓存
                 queueManagerCache.put(cacheKey, queueManager);
-                logger.info("********************获取或创建 IBM MQ 队列管理器实例 end");
+                Log.info("********************获取或创建 IBM MQ 队列管理器实例 end");
                 return queueManager;
             } catch (Exception e) {
                 // 记录连接失败的异常信息
-                logger.error("创建 IBM MQ 连接失败", e);
+                Log.error("创建 IBM MQ 连接失败", e);
                 return null;
             }
         }
@@ -428,12 +429,12 @@ ps -ef
                     queueManagerCache.put(cacheKey, queueManager);
                     return queueManager;
                 }else {
-                    logger.error("创建MQ队列管理器失败: 队列名为空{}", mqConfig);
+                    Log.error("创建MQ队列管理器失败: 队列名为空{}", mqConfig);
                     return null;
                 }
             } catch (Exception e) {
                 // 记录连接失败的异常信息
-                logger.error("创建 IBM MQ 连接失败", e);
+                Log.error("创建 IBM MQ 连接失败", e);
                 return null;
             }
         }
@@ -471,7 +472,7 @@ ps -ef
                 return queue;
             } catch (Exception e) {
                 // 记录队列绑定失败的异常信息
-                logger.error("IBM MQ 绑定队列失败", e);
+                Log.error("IBM MQ 绑定队列失败", e);
                 return null;
             }
         }
@@ -514,7 +515,7 @@ ps -ef
                 return queue;
             } catch (Exception e) {
                 // 记录队列绑定失败的异常信息
-                logger.error("IBM MQ 绑定队列失败", e);
+                Log.error("IBM MQ 绑定队列失败", e);
                 return null;
             }
         }
@@ -575,7 +576,7 @@ ps -ef
                 }
             } catch (MQException e) {
                 // 记录断开连接时发生的异常,但不中断后续执行
-                logger.error("关闭 IBM MQ 队列管理器失败", e);
+                Log.error("关闭 IBM MQ 队列管理器失败", e);
             } finally {
                 // 确保无论如何都使缓存条目失效以避免脏数据
                 queueManagerCache.invalidate(cacheKey);
@@ -591,7 +592,7 @@ ps -ef
                 }
             } catch (MQException e) {
                 // 记录断开连接时发生的异常,但不中断后续执行
-                logger.error("关闭 IBM MQ 队列失败", e);
+                Log.error("关闭 IBM MQ 队列失败", e);
             } finally {
                 // 确保无论如何都使缓存条目失效以避免脏数据
                 QueueCache.invalidate(cacheKey);

+ 16 - 15
src/main/java/com/bfkj/unidia/IOUtils/KafkaHelper.java

@@ -1,5 +1,6 @@
 package com.bfkj.unidia.IOUtils;
 
+import com.bfkj.unidia.logUtils.Log;
 import com.github.benmanes.caffeine.cache.Cache;
 import org.apache.kafka.clients.consumer.*;
 import org.apache.kafka.clients.producer.*;
@@ -93,7 +94,7 @@ public class KafkaHelper {
                 if (exception != null) {
                     if (firstError.get() == null) {
                         firstError.set(exception);
-                        logger.error("批量发送失败", exception);
+                        Log.error("批量发送失败", exception);
                         failList.add(record.value());
                     }
                 } else {
@@ -106,7 +107,7 @@ public class KafkaHelper {
             try {
                 boolean completed = latch.await(30, TimeUnit.SECONDS); // 捕获返回值
                 if (!completed) {
-                    logger.error("批量发送超时,强制关闭生产者");
+                    Log.error("批量发送超时,强制关闭生产者");
                     Thread.currentThread().interrupt();
                     producer.close(); // 主动关闭生产者释放资源
                     return Result.fail("批量发送超时超过30秒");
@@ -126,7 +127,7 @@ public class KafkaHelper {
             if(producer != null && cacheKey != null) {
                 closeProducer(cacheKey,producer);
             }
-            logger.error("批量处理异常", e);
+            Log.error("批量处理异常", e);
             return Result.fail("批量处理失败: " + e.getMessage());
         }
     }
@@ -190,7 +191,7 @@ public class KafkaHelper {
 
             //检查并启用幂等性保障
             if (!config.containsKey(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG)) {
-                logger.info("启用幂等性保障");
+                Log.info("启用幂等性保障");
                 config.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, "true");
             }
 
@@ -206,7 +207,7 @@ public class KafkaHelper {
 
             return Result.success(new KafkaProducer<>(props));
         } catch (Exception e) {
-            logger.error("创建Kafka生产者失败", e);
+            Log.error("创建Kafka生产者失败", e);
             return Result.fail("创建Kafka生产者失败: " + e.getMessage());
         }
     }
@@ -249,7 +250,7 @@ public class KafkaHelper {
             List<String> messages = new ArrayList<>();
             for (ConsumerRecord<String, String> record : records) {
                 messages.add(record.value());
-                logger.info("Kafka消费数据: {}", record.value());
+                Log.info("Kafka消费数据: {}", record.value());
             }
 
             if (!messages.isEmpty()) {
@@ -260,13 +261,13 @@ public class KafkaHelper {
                     return Result.fail("Kafka消费者{".concat(cacheKey).concat("}异常"));
                 }
             }
-            logger.info("消费数量:");
-            logger.info(String.valueOf(messages.size()));
-            if (messages.size()>0) logger.info(messages.get(0));
+            Log.info("消费数量:");
+            Log.info(String.valueOf(messages.size()));
+            if (messages.size()>0) Log.info(messages.get(0));
             return Result.success(messages);
         }catch (Exception e) {
             closeConsumer(cacheKey,consumer);
-            logger.error("Kafka消费异常{}",cacheKey, e);
+            Log.error("Kafka消费异常{}",cacheKey, e);
             return Result.fail("Kafka消费异常: " + e.getMessage());
         }
     }
@@ -370,7 +371,7 @@ public class KafkaHelper {
 
             // 检查最新偏移量
             Map<TopicPartition, Long> endOffsets = consumer.endOffsets(assignments);
-            logger.info("消费者最新偏移量: {}", endOffsets);
+            Log.info("消费者最新偏移量: {}", endOffsets);
             return !endOffsets.isEmpty();
         } catch (Exception e) {
             logger.warn("消费者健康检查失败", e);
@@ -411,7 +412,7 @@ public class KafkaHelper {
                 producer.close();
             }
         } catch (Exception e) {
-            logger.error("关闭生产者异常: {}", cacheKey, e);
+            Log.error("关闭生产者异常: {}", cacheKey, e);
         }finally {
             producerCache.invalidate(cacheKey);
         }
@@ -431,7 +432,7 @@ public class KafkaHelper {
                 consumer.close();
             }
         } catch (Exception e) {
-            logger.error("关闭生产者异常: {}", cacheKey, e);
+            Log.error("关闭生产者异常: {}", cacheKey, e);
         }finally {
             consumerCache.invalidate(cacheKey);
         }
@@ -441,9 +442,9 @@ public class KafkaHelper {
     public void destroy() {
         producerCache.asMap().forEach(KafkaHelper::closeProducer);
         producerCache.invalidateAll();
-        logger.info("生产者缓存清除");
+        Log.info("生产者缓存清除");
         consumerCache.asMap().forEach(KafkaHelper::closeConsumer);
         consumerCache.invalidateAll();
-        logger.info("消费者缓存清除");
+        Log.info("消费者缓存清除");
     }
 }

+ 9 - 8
src/main/java/com/bfkj/unidia/IOUtils/RabbitMQHelper.java

@@ -2,6 +2,7 @@ package com.bfkj.unidia.IOUtils;
 
 import com.bfkj.unidia.DataUtils.DataFormatConverter;
 import com.bfkj.unidia.Result;
+import com.bfkj.unidia.logUtils.Log;
 import com.github.benmanes.caffeine.cache.Cache;
 import com.github.benmanes.caffeine.cache.Caffeine;
 import com.rabbitmq.client.*;
@@ -60,12 +61,12 @@ public class RabbitMQHelper {
                 try {
                     channel.basicPublish(exchange, routingKey, null, msg.getBytes());
                 } catch (IOException e) {
-                    logger.error("RabbitMQ批量消息发送失败", e);
+                    Log.error("RabbitMQ批量消息发送失败", e);
                     failList.add(msg);
                 }
             }
         } catch (Exception e) {
-            logger.error("RabbitMQ批量发送异常", e);
+            Log.error("RabbitMQ批量发送异常", e);
             return Result.fail("RabbitMQ批量发送异常: " + e.getMessage());
         }
         return Result.success(failList);
@@ -107,11 +108,11 @@ public class RabbitMQHelper {
                 String message = new String(body);
                 return Result.success(message);
             } catch (IOException e) {
-                logger.error("RabbitMQ消息接收失败", e);
+                Log.error("RabbitMQ消息接收失败", e);
                 return Result.fail("消息接收失败: " + e.getMessage());
             }
         } catch (Exception e) {
-            logger.error("RabbitMQ接收异常", e);
+            Log.error("RabbitMQ接收异常", e);
             return Result.fail("RabbitMQ接收异常: " + e.getMessage());
         }
     }
@@ -150,7 +151,7 @@ public class RabbitMQHelper {
                 return newChannel;
             } catch (IOException | TimeoutException e) {
                 // 记录通道创建失败的异常信息
-                logger.error("创建RabbitMQ通道失败", e);
+                Log.error("创建RabbitMQ通道失败", e);
                 return null;
             }
         }
@@ -228,7 +229,7 @@ public class RabbitMQHelper {
                 connectionCache.put(cacheKey, newConnection);
                 return newConnection;
             } catch (IOException | TimeoutException e) {
-                logger.error("创建RabbitMQ连接失败", e);
+                Log.error("创建RabbitMQ连接失败", e);
                 throw e;
             }
         }
@@ -279,9 +280,9 @@ public class RabbitMQHelper {
         if (value instanceof AutoCloseable closeable) {
             try {
                 closeable.close();
-                logger.info("自动关闭{}缓存: {}", "缓存资源", key);
+                Log.info("自动关闭{}缓存: {}", "缓存资源", key);
             } catch (Exception e) {
-                logger.error("关闭{}缓存失败", "缓存资源", e);
+                Log.error("关闭{}缓存失败", "缓存资源", e);
             }
         }
     }

+ 7 - 6
src/main/java/com/bfkj/unidia/IOUtils/RocketMQHelper.java

@@ -2,6 +2,7 @@ package com.bfkj.unidia.IOUtils;
 
 import com.bfkj.unidia.DataUtils.DataFormatConverter;
 import com.bfkj.unidia.Result;
+import com.bfkj.unidia.logUtils.Log;
 import com.github.benmanes.caffeine.cache.Cache;
 import org.apache.rocketmq.client.apis.ClientConfiguration;
 import org.apache.rocketmq.client.apis.ClientException;
@@ -84,22 +85,22 @@ public class RocketMQHelper {
                 try {
                     byte[] body = DataFormatConverter.convertObjectToString(messageObj).getBytes(); // 将消息对象转换为字节数组
                     SendReceipt receipt = producer.send(buildMessage(topic, tag, body));
-                    logger.info("消息发送成功: {}", receipt.getMessageId());
+                    Log.info("消息发送成功: {}", receipt.getMessageId());
                 } catch (ClientException e) {
-                    logger.error("发送消息失败", e);
+                    Log.error("发送消息失败", e);
                     failList.add(messageObj.toString());
                 }
             }
             return Result.success(failList);
         } catch (Exception e) {
-            logger.error("RocketMQ 批量发送异常", e);
+            Log.error("RocketMQ 批量发送异常", e);
             return Result.fail("RocketMQ 批量发送异常: " + e.getMessage());
         } finally {
             if (producer != null) {
                 try {
                     producer.close();
                 } catch (Exception e) {
-                    logger.error("关闭生产者失败", e);
+                    Log.error("关闭生产者失败", e);
                 }
             }
         }
@@ -131,7 +132,7 @@ public class RocketMQHelper {
             }
             return Result.success("消费者启动成功");
         } catch (Exception e) {
-            logger.error("启动消费者失败", e);
+            Log.error("启动消费者失败", e);
             return Result.fail("启动消费者失败: " + e.getMessage());
         }
     }
@@ -164,7 +165,7 @@ public class RocketMQHelper {
                 producerCache.put(cacheKey, producer);
                 return producer;
             } catch (ClientException e) {
-                logger.error("创建生产者失败", e);
+                Log.error("创建生产者失败", e);
                 return null;
             }
         }

+ 4 - 3
src/main/java/com/bfkj/unidia/OpenApi/DataProcessApi.java

@@ -4,6 +4,7 @@ package com.bfkj.unidia.OpenApi;
 import com.bfkj.unidia.Result;
 import com.bfkj.unidia.Core.DataServices;
 
+import com.bfkj.unidia.logUtils.Log;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.http.ResponseEntity;
@@ -62,7 +63,7 @@ public class DataProcessApi {
         try {
             // 检查请求是否为空,如果为空,则记录日志并返回错误响应
             if(request == null || request.isEmpty()){
-                logger.info("dataprocess/" + url + "收到空请求");
+                Log.info("dataprocess/" + url + "收到空请求");
                 return ResponseEntity.ok(Result.fail("接收空数据"));
             }
             // 如果事件参数不为空,则将其添加到请求数据中
@@ -74,11 +75,11 @@ public class DataProcessApi {
             return ResponseEntity.ok(result);
         } catch (IllegalArgumentException e) {
             // 捕获非法参数异常,并返回错误响应
-            logger.info("dataprocess/" + url + "参数错误: ",e);
+            Log.info("dataprocess/" + url + "参数错误: ",e);
             return ResponseEntity.badRequest().body(Result.fail("参数错误: " + e.getMessage()));
         } catch (Exception e) {
             // 捕获其他异常,并返回内部服务器错误响应
-            logger.info("dataprocess/" + url + "服务失败: ",e);
+            Log.info("dataprocess/" + url + "服务失败: ",e);
             return ResponseEntity.status(500).body(Result.fail("服务失败: " + e.getMessage()));
         }
     }

+ 2 - 1
src/main/java/com/bfkj/unidia/OpenApi/ServiceControllerApi.java

@@ -3,6 +3,7 @@ package com.bfkj.unidia.OpenApi;
 import com.bfkj.unidia.Result;
 import com.bfkj.unidia.Core.ServiceController;
 
+import com.bfkj.unidia.logUtils.Log;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.http.ResponseEntity;
@@ -47,7 +48,7 @@ public class ServiceControllerApi {
     private ResponseEntity<Result<Integer>> controller(Map<String,String> request,String controllerType){
         try {
             if(request == null || request.isEmpty()){
-                logger.info("services/".concat(controllerType).concat("收到空请求"));
+                Log.info("services/".concat(controllerType).concat("收到空请求"));
                 return ResponseEntity.ok(Result.fail("接收空数据"));
             }
             Result<Integer> result;

+ 15 - 12
src/main/java/com/bfkj/unidia/SystemEnvInitializer.java

@@ -2,6 +2,7 @@ package com.bfkj.unidia;
 
 import com.bfkj.unidia.DataBaseUtils.DbExecutor;
 import com.bfkj.unidia.Core.ServiceController;
+import com.bfkj.unidia.logUtils.Log;
 import org.jetbrains.annotations.NotNull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -36,12 +37,13 @@ import java.util.concurrent.TimeUnit;
 @EnableScheduling
 public class SystemEnvInitializer implements ApplicationListener<ApplicationReadyEvent> {
     private static final Logger logger = LoggerFactory.getLogger(SystemEnvInitializer.class);
+
     private final SystemEnvCache envCache;//全局常量缓存
     private final DbExecutor  dbExecutor;//数据库操作类,兼容insert or update
     private final ServiceController serviceController; //服务控制类,用于启动本容器的服务
     private ScheduledExecutorService heartbeatScheduler;//容器心跳线程
     // 使用构造函数注入(推荐):
-    public SystemEnvInitializer(SystemEnvCache envCache,DbExecutor  dbExecutor,ServiceController serviceController) {
+    public SystemEnvInitializer(SystemEnvCache envCache,DbExecutor  dbExecutor,ServiceController serviceController ) {
         this.envCache = envCache;
         this.dbExecutor = dbExecutor;
         this.serviceController = serviceController;
@@ -95,17 +97,17 @@ public class SystemEnvInitializer implements ApplicationListener<ApplicationRead
 
             Result<Integer> regContainerResult = regContainer(systemInfo,containerCode,dbConfig);//执行容器自动注册流程
             if (regContainerResult.isSuccess()) {
-                logger.info("容器自动注册成功");
+                Log.info("容器自动注册成功");
                 startService(containerCode);//启动核心业务服务
                 startHeartbeatTask(containerCode, dbConfig);//激活心跳检测机制
             } else {
-                logger.info("容器自动注册失败:" + regContainerResult.getError());
+                Log.info("容器自动注册失败:" + regContainerResult.getError());
                 return;
                 // 注册失败处理逻辑(需实现重试机制以及降级处理)
             }
-            logger.info("系统环境初始化完成,缓存信息: {}", envCache.getImmutableView());
+            Log.info("系统环境初始化完成,缓存信息: {}", envCache.getImmutableView());
         } catch (Exception e) {//初始化异常处理流程
-            logger.error("系统环境初始化失败", e);//记录错误日志
+            Log.error("系统环境初始化失败", e);//记录错误日志
             throw new RuntimeException("系统环境初始化失败", e);//并抛出运行时异常终止启动过程
         }
     }
@@ -157,7 +159,7 @@ public class SystemEnvInitializer implements ApplicationListener<ApplicationRead
         if (!Files.exists(path)) {
             // 创建多级目录结构并记录日志
             Files.createDirectories(path);
-            logger.info("创建目录: {}", path.toAbsolutePath());
+            Log.info("创建目录: {}", path.toAbsolutePath());
         }
     }
     /**
@@ -203,7 +205,7 @@ public class SystemEnvInitializer implements ApplicationListener<ApplicationRead
         String containerCode = ipAddress + ":" + port;
         // 更新环境缓存中的容器编码
         envCache.put("container_code", containerCode);
-        logger.info("应用IP地址已缓存: {}", ipAddress);
+        Log.info("应用IP地址已缓存: {}", ipAddress);
         return containerCode;
     }
 
@@ -254,11 +256,11 @@ public class SystemEnvInitializer implements ApplicationListener<ApplicationRead
      */
     private void startService(String containerCode){
         // 调用服务控制器启动容器服务并处理执行结果
-        logger.info("启动服务...");
+        Log.info("启动服务...");
         serviceController.startService(containerCode,null);
 
         // 启动单一运行模式服务的定时竞争机制
-        logger.info("启动单一竞争服务...");
+        Log.info("启动单一竞争服务...");
         serviceController.handleCompetitiveService();
     }
 
@@ -290,12 +292,13 @@ public class SystemEnvInitializer implements ApplicationListener<ApplicationRead
                 Result<Integer> result = dbExecutor.update(dbConfig, containerTableName, params);//执行数据库更新操作
 
                 if (result.isSuccess()) {
-                    logger.info("心跳更新成功,影响记录数: {}", result.getData());
+                    Log.info("data",result);
+                    Log.info("心跳更新成功,影响记录数: {}", result.getData());
                 } else {
                     logger.warn("心跳更新失败: {}", result.getError());
                 }
             } catch (Exception e) {
-                logger.error("执行心跳任务异常", e);
+                Log.error("执行心跳任务异常", e);
             }
         }, 0, heartbeatInterval, TimeUnit.SECONDS);//初始延迟0秒,后续每隔heartbeatInterval秒执行一次
     }
@@ -304,7 +307,7 @@ public class SystemEnvInitializer implements ApplicationListener<ApplicationRead
     public void destroy() {
         if (heartbeatScheduler != null) {
             heartbeatScheduler.shutdownNow();
-            logger.info("心跳定时任务已关闭");
+            Log.info("心跳定时任务已关闭");
         }
     }
 }

+ 3 - 2
src/main/java/com/bfkj/unidia/cacheUtils/CacheUtil.java

@@ -1,5 +1,6 @@
 package com.bfkj.unidia.cacheUtils;
 
+import com.bfkj.unidia.logUtils.Log;
 import com.github.benmanes.caffeine.cache.Cache;
 import com.github.benmanes.caffeine.cache.Caffeine;
 import org.slf4j.Logger;
@@ -45,9 +46,9 @@ public class CacheUtil {
         if (value instanceof AutoCloseable closeable) {
             try {
                 closeable.close();
-                logger.info("自动关闭{}缓存: {}", "缓存资源", key);
+                Log.info("自动关闭{}缓存: {}", "缓存资源", key);
             } catch (Exception e) {
-                logger.error("关闭{}缓存失败", "缓存资源", e);
+                Log.error("关闭{}缓存失败", "缓存资源", e);
             }
         }
     }

+ 250 - 0
src/main/java/com/bfkj/unidia/logUtils/Log.java

@@ -0,0 +1,250 @@
+package com.bfkj.unidia.logUtils;
+
+import com.bfkj.unidia.DataBaseUtils.DbExecutor;
+import com.bfkj.unidia.Result;
+import com.bfkj.unidia.SystemEnvCache;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import jakarta.annotation.PostConstruct;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.DependsOn;
+import org.springframework.stereotype.Component;
+
+import java.util.*;
+
+/**
+ * 增强版日志工具类(带持久化功能)
+ */
+@Component
+@DependsOn("systemEnvCache")
+public class Log {
+    // 静态持有依赖的Bean
+    private static SystemEnvCache systemEnvCache;
+    private static DbExecutor dbExecutor;
+
+    // 实例字段用于注入
+    private SystemEnvCache initializeLoggingSystemCache;
+    private DbExecutor initializeLoggingSystemExec;
+    @Autowired
+    public void LogUtils(SystemEnvCache cache, DbExecutor executor) {
+        this.initializeLoggingSystemCache = cache;
+        this.initializeLoggingSystemExec = executor;
+    }
+
+    @PostConstruct
+    public void init() {
+        // 将注入的Bean赋值给静态变量
+        systemEnvCache = this.initializeLoggingSystemCache;
+        dbExecutor = this.initializeLoggingSystemExec;
+
+    }
+
+
+
+    // 获取调用者类名的Logger
+    private static Logger getLogger() {
+        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+        // 调用链:0-getStackTrace, 1-getLogger, 2-调用方法, 3-实际调用类
+        return LoggerFactory.getLogger(stackTrace[3].getClassName());
+    }
+
+    /**
+     * 核心记录方法(实际持久化逻辑)
+     * @param level 日志级别
+     * @param message 日志内容
+     * @param args 参数
+     * @param throwable 异常对象
+     */
+    private static void record(String level, String message, Object[] args, Throwable throwable) {
+        // 这里实现您的自定义持久化逻辑
+        try {
+            Map<String, Object> logRecord = new HashMap<>();
+            logRecord.put("timestamp", System.currentTimeMillis());
+            logRecord.put("level", level);
+            logRecord.put("thread", Thread.currentThread().getName());
+            
+            // 获取调用类和方法信息
+            StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+            if (stackTrace.length > 4) {
+                logRecord.put("className", stackTrace[4].getClassName());
+                logRecord.put("methodName", stackTrace[4].getMethodName());
+                logRecord.put("lineNumber", stackTrace[4].getLineNumber());
+            }
+            
+            // 格式化消息(如果使用占位符)
+            String formattedMsg = message;
+            if (args != null && args.length > 0) {
+                formattedMsg = formatMessage(message, args);
+            }
+            logRecord.put("message", formattedMsg);
+            
+            if (throwable != null) {
+                logRecord.put("exception", throwable.getClass().getName());
+                logRecord.put("exceptionMessage", throwable.getMessage());
+                // 可以添加堆栈信息
+                 logRecord.put("stackTrace", ExceptionUtils.getStackTrace(throwable));
+            }
+            
+            // 调用您的持久化实现
+            if (Objects.isNull(logRecord))return;
+            // 持久化方式:将日志记录到数据库中
+            save(logRecord);
+            // .....
+
+        } catch (Exception e) {
+            // 持久化失败时不影响正常日志记录
+            getLogger().error("Failed to persist log record", e);
+        }
+    }
+
+    /**
+     * 格式化带占位符的消息
+     */
+    private static String formatMessage(String format, Object... args) {
+        if (format == null) return "";
+        if (args == null || args.length == 0) return format;
+        
+        for (Object arg : args) {
+            format = format.replaceFirst("\\{\\}", String.valueOf(arg));
+        }
+        return format;
+    }
+
+    // ========== 以下是公开的日志方法 ==========
+
+    public static void trace(String msg) {
+        getLogger().trace(msg);
+        record("TRACE", msg, null, null);
+    }
+
+    public static void trace(String format, Object... args) {
+        getLogger().trace(format, args);
+        record("TRACE", format, args, null);
+    }
+
+    public static void debug(String msg) {
+        getLogger().debug(msg);
+        record("DEBUG", msg, null, null);
+    }
+
+    public static void debug(String format, Object... args) {
+        getLogger().debug(format, args);
+        record("DEBUG", format, args, null);
+    }
+
+    public static void info(String msg) {
+        getLogger().info(msg);
+        record("INFO", msg, null, null);
+    }
+
+    public static void info(String format, Object... args) {
+        getLogger().info(format, args);
+        record("INFO", format, args, null);
+    }
+
+    public static void warn(String msg) {
+        getLogger().warn(msg);
+        record("WARN", msg, null, null);
+    }
+
+    public static void warn(String format, Object... args) {
+        getLogger().warn(format, args);
+        record("WARN", format, args, null);
+    }
+
+    public static void error(String msg) {
+        getLogger().error(msg);
+        record("ERROR", msg, null, null);
+    }
+
+    public static void error(String format, Object... args) {
+        getLogger().error(format, args);
+        record("ERROR", format, args, null);
+    }
+
+    public static void error(String msg, Throwable t) {
+        getLogger().error(msg, t);
+        record("ERROR", msg, null, t);
+    }
+
+    /**
+     * 记录方法入参日志(DEBUG级别)
+     */
+    public static void logMethodEntry(String methodName, Object... params) {
+        if (getLogger().isDebugEnabled()) {
+            StringBuilder sb = new StringBuilder("Entering method [")
+                .append(methodName)
+                .append("] with params: ");
+            
+            for (int i = 0; i < params.length; i++) {
+                sb.append("\n  arg[").append(i).append("]: ").append(params[i]);
+            }
+            String msg = sb.toString();
+            getLogger().debug(msg);
+            record("DEBUG", msg, null, null);
+        }
+    }
+
+    /**
+     * 记录方法返回值日志(DEBUG级别)
+     */
+    public static void logMethodExit(String methodName, Object result) {
+        if (getLogger().isDebugEnabled()) {
+            String msg = "Exiting method [" + methodName + "], return: " + result;
+            getLogger().debug(msg);
+            record("DEBUG", msg, null, null);
+        }
+    }
+
+    /**
+     * 自定义业务日志(直接持久化+打印日志)
+     */
+    public static void businessLog(String module, String action, String message) {
+        String formatted = String.format("[%s] %s: %s", module, action, message);
+        info(formatted);
+        
+        // 额外业务字段持久化
+        Map<String, Object> bizRecord = new HashMap<>();
+        bizRecord.put("module", module);
+        bizRecord.put("action", action);
+        bizRecord.put("businessMessage", message);
+        bizRecord.put("logLevel", "INFO");
+        
+        // 调用您的持久化实现
+//        YourPersistenceService.saveBusinessLog(bizRecord);
+    }
+
+
+    public static void save(Object logRecord) {
+        Map<String, Object> logMap = new LinkedHashMap<>();
+        logMap.put("logType", "service");
+        ObjectMapper mapper = new ObjectMapper();
+        Map<String, Object> dataMap = mapper.convertValue(logRecord,
+                new TypeReference<Map<String, Object>>() {});
+        dataMap.putAll(logMap);
+        String jsonData = null;
+        try {
+            jsonData = new ObjectMapper().writeValueAsString(dataMap);
+        } catch (JsonProcessingException e) {
+            getLogger().info("日志记录失败");
+        }
+        if (Objects.isNull(dbExecutor)|| Objects.isNull(systemEnvCache))return;
+        //todo 创建表sql
+        Result<Integer> result = dbExecutor.dbUpdate(systemEnvCache.getDbInfo(), "log_record",
+                Map.of("dataContent", Map.of(
+                        "data", Map.of(
+                                "time", new Date().getTime(),
+                                "target", jsonData,
+                                "type", "service"
+                        )
+                ), "event", "INSERT")
+        );
+        if (result.isSuccess()&&result.getData()!=null){
+            getLogger().info("日志记录成功!");
+        }
+    }
+}

+ 25 - 0
src/main/java/com/bfkj/unidia/logUtils/SpringContextHolder.java

@@ -0,0 +1,25 @@
+package com.bfkj.unidia.logUtils;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SpringContextHolder implements ApplicationContextAware {
+    
+    private static ApplicationContext applicationContext;
+    
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        SpringContextHolder.applicationContext = applicationContext;
+    }
+    
+    public static <T> T getBean(Class<T> clazz) {
+        return applicationContext.getBean(clazz);
+    }
+    
+    public static Object getBean(String name) {
+        return applicationContext.getBean(name);
+    }
+}