andy 8 сар өмнө
parent
commit
953791421c

+ 17 - 0
mainFactory/src/main/java/org/bfkj/utils/LogUtils.java

@@ -5,6 +5,8 @@ import org.bfkj.config.AppConfig;
 import org.bfkj.config.ElasticsearchConfig;
 import org.bfkj.config.SpringContextApplication;
 import org.bfkj.protocol.ElasticHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 
 import java.text.SimpleDateFormat;
@@ -15,11 +17,26 @@ public class LogUtils { // 依据服务编号ID获取服务类型,如果是异
     public static Map<String, List<Object>> logErrorMapList = new HashMap<>();
     public static Map<String, List<Object>> logSuccessMapList = new HashMap<>();
     public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    
+    private static final Logger logger = LoggerFactory.getLogger(LogUtils.class);
     public static  void log(String location, String success, Object calculationLocation, String logContent, String serviceId,  Object iNDataContent, String dataObjectId, Object OutDataContent, Object event) {
         ThreadPoolTaskExecutor threadPoolTaskExecutor = SpringContextApplication.getBean("ThreadPoolTaskExecutor");
         threadPoolTaskExecutor.submit(() ->
                 logWrite(location, success, calculationLocation, logContent, serviceId, iNDataContent, dataObjectId, OutDataContent, event)
         );
+        threadPoolTaskExecutor.submit(() ->
+                logger.info("""
+                                    location: {};
+                                    result: {};
+                                    calculation location: {};
+                                    content: {};
+                                    service id: {};
+                                    input data content: {};
+                                    data object id: {};
+                                    output data content: {};
+                                    event: {}
+                                    """,location,success,calculationLocation,logContent,serviceId,iNDataContent,dataObjectId,OutDataContent,event)
+        );
     }
 
     public static void logWrite(String location, String success, Object calculationLocation, String logContent, String serviceId, Object iNDataContent, String dataObjectId, Object OutDataContent, Object event) {

+ 40 - 0
mainFactory/src/main/resources/logback-spring.xml

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration scan="true" scanPeriod="1 minute" debug="false">
+
+    <!-- 定义日志文件的目录 -->
+    <property name="LOGS" value="./logs" />
+    <property name="LOG_PATTERN" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" />
+
+    <!-- 控制台输出配置 -->
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>${LOG_PATTERN}</pattern>
+        </encoder>
+    </appender>
+
+    <!-- 日志文件滚动策略,结合时间和大小 -->
+    <appender name="ROLLING_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <file>${LOGS}/app.log</file>
+        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
+            <!-- 日志文件按天滚动 -->
+            <fileNamePattern>${LOGS}/app.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
+            <!-- 每个日志文件的最大大小,例如10MB -->
+            <maxFileSize>10MB</maxFileSize>
+            <!-- 保留最近30天的日志文件 -->
+            <maxHistory>30</maxHistory>
+        </rollingPolicy>
+        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+            <!-- 触发滚动的文件大小 -->
+            <MaxFileSize>10MB</MaxFileSize>
+        </triggeringPolicy>
+        <encoder>
+            <pattern>${LOG_PATTERN}</pattern>
+        </encoder>
+    </appender>
+
+    <!-- 设置日志级别 -->
+    <root level="info">
+        <appender-ref ref="STDOUT" />
+        <appender-ref ref="ROLLING_FILE" />
+    </root>
+</configuration>