Compare commits

...

20 Commits

Author SHA1 Message Date
22fc150557 fix: remove the fields: contactEmail,contactPhone,contactPhoneCountry from the DriverConvertDTO 2025-08-18 16:49:26 +08:00
ac5aafcada fix: modify the log4j2.xml 2025-08-07 15:03:46 +08:00
48c4527c38 fix: modify the log4j2.xml 2025-08-06 11:27:46 +08:00
49a5223f7e fix: modify the post-steps.sh 2025-08-06 10:34:21 +08:00
11565a4311 fix: modify the post-steps.sh 2025-08-06 10:31:39 +08:00
d4b71bab78 fix: modify the post-steps.sh 2025-08-06 10:28:09 +08:00
da5eed39fb fix: modify the post-steps.sh 2025-08-06 10:23:47 +08:00
9ddb56fc7e fix: modify the post-steps.sh 2025-08-06 09:58:05 +08:00
dc70f38e29 feature: add log system 2025-08-06 09:24:20 +08:00
bc409e516f fix: try-catch the field is null exception 2025-08-05 10:49:31 +08:00
f61dac4b61 feature: process the compare of driver 2025-07-23 11:05:51 +08:00
6d8fcd0f30 add some logs 2025-07-23 09:23:31 +08:00
8528f173a6 catch webClient error 2025-07-23 09:12:14 +08:00
81acee7ce0 add listening address 2025-07-18 10:56:32 +08:00
4e613004fc test webhook 2025-07-18 10:50:57 +08:00
42cf919c30 Merge branch 'master' of 34.102.70.200:ALEX/pro_eld_mqtt_compare 2025-07-18 10:49:52 +08:00
9e472e204d Merge branch 'master' of 34.102.70.200:ALEX/pro_eld_mqtt_compare 2025-07-18 10:49:23 +08:00
8d92108589 commit 2025-07-18 02:41:20 +00:00
440544b0ff commit 2025-07-18 02:25:48 +00:00
74d44f14b1 commit 2025-07-18 02:24:52 +00:00
12 changed files with 260 additions and 41 deletions

7
bin/post-steps.sh Normal file → Executable file
View File

@@ -1,8 +1,9 @@
#!/bin/bash #!/bin/bash
PORT=8889 PORT=8889
JAR_PATH="/home/zhangbiqiong/pro_eld_mqtt_compare/app/pro_eld_mqtt_compare-0.0.1-SNAPSHOT.jar" JAR_PATH="/home/zhangbiqiong/pro_eld_mqtt_compare/target/pro_eld_mqtt_compare-0.0.1-SNAPSHOT.jar"
LOG_PATH="/home/zhangbiqiong/pro_eld_mqtt_compare/logs/pro_eld_mqtt_compare.log"
cd /home/zhangbiqiong/pro_eld_mqtt_compare || { echo "Failed to cd"; exit 1; }
# 检测端口是否被占用 # 检测端口是否被占用
if netstat -tuln | grep -q ":$PORT"; then if netstat -tuln | grep -q ":$PORT"; then
@@ -10,6 +11,6 @@ if netstat -tuln | grep -q ":$PORT"; then
exit 0 exit 0
else else
echo "Port $PORT is free. Starting application..." echo "Port $PORT is free. Starting application..."
nohup java -jar "$JAR_PATH" > "$LOG_PATH" 2>&1 & nohup java -jar "$JAR_PATH" > /dev/null 2>&1 &
echo "Application started with PID $!" echo "Application started with PID $!"
fi fi

0
bin/pre-steps.sh Normal file → Executable file
View File

22
pom.xml
View File

@@ -17,6 +17,12 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
@@ -44,16 +50,6 @@
<artifactId>spring-boot-starter-webflux</artifactId> <artifactId>spring-boot-starter-webflux</artifactId>
<version>3.3.5</version> <version>3.3.5</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.19.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
@@ -79,6 +75,12 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId> <artifactId>spring-boot-starter-integration</artifactId>
</dependency> </dependency>
<!-- 替换默认日志系统为 Log4j2 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>

View File

@@ -9,4 +9,4 @@ public class ProEldMqttCompareApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(ProEldMqttCompareApplication.class, args); SpringApplication.run(ProEldMqttCompareApplication.class, args);
} }
} }

View File

@@ -24,7 +24,7 @@ public class StartupCompareRunner implements ApplicationRunner {
// compareService.compare(5, "vehicle"); // compareService.compare(5, "vehicle");
// compareService.compare(5, "device"); // compareService.compare(5, "device");
// compareService.compare(5, "business"); // compareService.compare(5, "business");
// compareService.compare(5, "driver"); compareService.compare(5, "driver");
// compareService.compare(5, "vehicle_device"); // compareService.compare(5, "vehicle_device");
// compareService.compare(5, "driver_vehicle"); // compareService.compare(5, "driver_vehicle");
// compareService.compare(5, "business_driver"); // compareService.compare(5, "business_driver");

View File

@@ -11,6 +11,7 @@ import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -46,7 +47,8 @@ public class ApiService {
public <T> Mono<List<T>> getInfoPakistan(GetInfoVO getInfoVO) { public <T> Mono<List<T>> getInfoPakistan(GetInfoVO getInfoVO) {
ParameterizedTypeReference<List<T>> typeRef = (ParameterizedTypeReference<List<T>>) tableObjectMapping.get(getInfoVO.getTableName()); ParameterizedTypeReference<List<T>> typeRef = (ParameterizedTypeReference<List<T>>) tableObjectMapping.get(getInfoVO.getTableName());
if (typeRef == null) { if (typeRef == null) {
throw new IllegalArgumentException("不支持该表名: " + getInfoVO.getTableName()); log.error("Pakistan API - 不支持该表名 : {}", getInfoVO.getTableName());
return Mono.empty();
} }
return webClientBuilder return webClientBuilder
@@ -58,7 +60,11 @@ public class ApiService {
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.bodyValue(getInfoVO) .bodyValue(getInfoVO)
.retrieve() .retrieve()
.bodyToMono(typeRef); .bodyToMono(typeRef)
.onErrorResume(e -> {
log.warn("Pakistan API - WebClient 请求 eldData 失败,错误: {}", e.getMessage());
return Mono.just(Collections.emptyList());
});
} }
// Pro API // Pro API
@@ -66,7 +72,8 @@ public class ApiService {
public <T> Mono<List<T>> getInfoPro(Integer customerId, String tableName) { public <T> Mono<List<T>> getInfoPro(Integer customerId, String tableName) {
ParameterizedTypeReference<List<T>> typeRef = (ParameterizedTypeReference<List<T>>) tableObjectMapping.get(tableName); ParameterizedTypeReference<List<T>> typeRef = (ParameterizedTypeReference<List<T>>) tableObjectMapping.get(tableName);
if (typeRef == null) { if (typeRef == null) {
throw new IllegalArgumentException("Unsupported table name: " + tableName); log.error("Pro API - 不支持该表名 : {}", tableName);
return Mono.empty();
} }
return webClientBuilder.baseUrl("https://eldapp.anytrek.app") return webClientBuilder.baseUrl("https://eldapp.anytrek.app")
@@ -79,6 +86,10 @@ public class ApiService {
.build()) .build())
.header("eldKey", "435e833ca0610442d25b8011475c8352") .header("eldKey", "435e833ca0610442d25b8011475c8352")
.retrieve() .retrieve()
.bodyToMono(typeRef); .bodyToMono(typeRef)
.onErrorResume(e -> {
log.warn("Pro API - WebClient 请求 eldData 失败,错误: {}", e.getMessage());
return Mono.just(Collections.emptyList());
});
} }
} }

View File

@@ -0,0 +1,24 @@
package com.ctgu.pro_eld_mqtt_compare.response;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
/**
* @ClassName DriverConvertDTO
* @Author Alex2
* @Date 2025/7/23 9:59
**/
@Data
public class DriverConvertDTO {
private Integer id;
private String name;
private String email;
private String phone;
private String firstName;
private String lastName;
// private String contactEmail;
// private String contactPhone;
// private String contactPhoneCountry;
private Integer isDelete;
private Integer customerId;
}

View File

@@ -1,5 +1,6 @@
package com.ctgu.pro_eld_mqtt_compare.response; package com.ctgu.pro_eld_mqtt_compare.response;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data; import lombok.Data;
/** /**
@@ -8,11 +9,30 @@ import lombok.Data;
* @Date 2025/7/4 15:19 * @Date 2025/7/4 15:19
**/ **/
@Data @Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class DriverDTO { public class DriverDTO {
private Integer id; private Integer id;
private String name; private String name;
private String email; private String email;
private String phone; private String phone;
private Content content;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public static class Content {
private String firstName;
private String lastName;
private String contactEmail;
private ContactPhone contactPhone;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public static class ContactPhone {
private String value;
private String country;
}
}
private Integer isDelete; private Integer isDelete;
private Integer customerId; private Integer customerId;
} }

View File

@@ -3,11 +3,13 @@ package com.ctgu.pro_eld_mqtt_compare.service;
import com.ctgu.pro_eld_mqtt_compare.api.ApiService; import com.ctgu.pro_eld_mqtt_compare.api.ApiService;
import com.ctgu.pro_eld_mqtt_compare.request.GetInfoVO; import com.ctgu.pro_eld_mqtt_compare.request.GetInfoVO;
import com.ctgu.pro_eld_mqtt_compare.request.PublishMQTTVO; import com.ctgu.pro_eld_mqtt_compare.request.PublishMQTTVO;
import com.ctgu.pro_eld_mqtt_compare.response.DriverConvertDTO;
import com.ctgu.pro_eld_mqtt_compare.response.DriverDTO;
import com.ctgu.pro_eld_mqtt_compare.utils.TAG; import com.ctgu.pro_eld_mqtt_compare.utils.TAG;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -19,7 +21,7 @@ import java.util.stream.Collectors;
* @Author Alex2 * @Author Alex2
* @Date 2025/7/4 10:34 * @Date 2025/7/4 10:34
**/ **/
@Slf4j @Log4j2
@Service @Service
public class CompareService { public class CompareService {
@@ -44,38 +46,122 @@ public class CompareService {
CompareService.apiService = apiService; CompareService.apiService = apiService;
} }
// 生成 value 组合 /**
* @Author: Alex
* @Description: 生成 value 组合
*/
private static String getValue(Map<String, Object> item, List<String> fieldNames) { private static String getValue(Map<String, Object> item, List<String> fieldNames) {
return fieldNames.stream() return fieldNames.stream()
.map(field -> String.valueOf(item.get(field))) .map(field -> String.valueOf(item.get(field)))
.collect(Collectors.joining("-")); .collect(Collectors.joining("-"));
} }
// 获取 value 字段 /**
* @Author: Alex
* @Description: 获取 value 字段
*/
private static List<String> getValueField(String tableName) { private static List<String> getValueField(String tableName) {
List<String> valueFields = KEY_FIELDS.get(tableName); List<String> valueFields = null;
if (valueFields == null) { try {
throw new IllegalArgumentException("未配置字段列表: " + tableName); valueFields = KEY_FIELDS.get(tableName);
if (valueFields == null) {
throw new IllegalArgumentException("未配置字段列表: " + tableName);
}
} catch (IllegalArgumentException e) {
log.error(e.getMessage());
return Collections.emptyList();
} }
return valueFields; return valueFields;
} }
// 比较 /**
* @Author: Alex
* @Description: 根据表名分发到 driver 或 common 处理
*/
public PublishMQTTVO compare(Integer customerId, String tableName) throws JsonProcessingException { public PublishMQTTVO compare(Integer customerId, String tableName) throws JsonProcessingException {
// Pakistan API if ("driver".equalsIgnoreCase(tableName)) {
GetInfoVO driverVehicle = new GetInfoVO(customerId, tableName); return compareDriver(customerId, tableName);
List<Object> postResultList = apiService.getInfoPakistan(driverVehicle).block(); } else {
List<Map<String, Object>> pakistanList = mapper.convertValue(postResultList, new TypeReference<List<Map<String, Object>>>() { return compareCommon(customerId, tableName);
}); }
}
// Pro API /**
* @Author: Alex
* @Description: 处理 driver 表
*/
public PublishMQTTVO compareDriver(Integer customerId, String tableName) throws JsonProcessingException {
// Pakistan 数据
GetInfoVO getInfoVO = new GetInfoVO(customerId, tableName);
List<Object> postResultList = apiService.getInfoPakistan(getInfoVO).block();
List<DriverConvertDTO> pakistanDTOs = compareDriverTable(postResultList); // driver表特有的数据类型转换
List<Map<String, Object>> pakistanList = mapper.convertValue(pakistanDTOs, new TypeReference<List<Map<String, Object>>>() {});
// Pro 数据
List<Object> getResultList = apiService.getInfoPro(customerId, tableName).block(); List<Object> getResultList = apiService.getInfoPro(customerId, tableName).block();
String json2 = mapper.writeValueAsString(getResultList); List<DriverConvertDTO> proDTOs = compareDriverTable(getResultList); // driver表特有的数据类型转换
List<Map<String, Object>> proList = mapper.readValue(json2, new TypeReference<List<Map<String, Object>>>() { List<Map<String, Object>> proList = mapper.convertValue(proDTOs, new TypeReference<List<Map<String, Object>>>() {});
});
return compareList(customerId, tableName, pakistanList, proList); return compareList(customerId, tableName, pakistanList, proList);
} }
/**
* @Author: Alex
* @Description: 处理通用表(如 vehicle、device 等)
*/
public PublishMQTTVO compareCommon(Integer customerId, String tableName) throws JsonProcessingException {
// Pakistan 数据
GetInfoVO getInfoVO = new GetInfoVO(customerId, tableName);
List<Object> postResultList = apiService.getInfoPakistan(getInfoVO).block();
List<Map<String, Object>> pakistanList = mapper.convertValue(postResultList, new TypeReference<List<Map<String, Object>>>() {});
// Pro 数据
List<Object> getResultList = apiService.getInfoPro(customerId, tableName).block();
String json = mapper.writeValueAsString(getResultList);
List<Map<String, Object>> proList = mapper.readValue(json, new TypeReference<List<Map<String, Object>>>() {});
return compareList(customerId, tableName, pakistanList, proList);
}
/**
* @Author: Alex
* @Description: 将 DriverDTO 列表转换为扁平结构 DriverConvertDTO 列表
*/
public List<DriverConvertDTO> compareDriverTable(List<Object> list) {
List<DriverConvertDTO> driverConvertDTOS = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
if (list != null) {
for (Object obj : list) {
DriverDTO driverDTO = mapper.convertValue(obj, DriverDTO.class);
DriverConvertDTO dto = new DriverConvertDTO();
dto.setId(driverDTO.getId());
dto.setName(driverDTO.getName());
dto.setEmail(driverDTO.getEmail());
dto.setPhone(driverDTO.getPhone());
dto.setCustomerId(driverDTO.getCustomerId());
dto.setIsDelete(driverDTO.getIsDelete());
if (driverDTO.getContent() != null) {
dto.setFirstName(driverDTO.getContent().getFirstName());
dto.setLastName(driverDTO.getContent().getLastName());
// dto.setContactEmail(driverDTO.getContent().getContactEmail());
// if (driverDTO.getContent().getContactPhone() != null) {
// dto.setContactPhone(driverDTO.getContent().getContactPhone().getValue());
// dto.setContactPhoneCountry(driverDTO.getContent().getContactPhone().getCountry());
// }
}
driverConvertDTOS.add(dto);
}
}
log.info("driverConvertDTOS : {}", driverConvertDTOS);
return driverConvertDTOS;
}
// 比较列表 // 比较列表
// public void compareList(Integer customerId, String tableName, List<Map<String, Object>> pakistanList, List<Map<String, Object>> proList) { // public void compareList(Integer customerId, String tableName, List<Map<String, Object>> pakistanList, List<Map<String, Object>> proList) {
// List<String> valueFields = getValueField(tableName); // List<String> valueFields = getValueField(tableName);
@@ -102,15 +188,19 @@ public class CompareService {
// } // }
// } // }
/**
* @Author: Alex
* @Description: 比较两侧数据
*/
public PublishMQTTVO compareList(Integer customerId, String tableName, List<Map<String, Object>> pakistanList, List<Map<String, Object>> proList) { public PublishMQTTVO compareList(Integer customerId, String tableName, List<Map<String, Object>> pakistanList, List<Map<String, Object>> proList) {
List<String> valueFields = getValueField(tableName); List<String> valueFields = getValueField(tableName);
Map<String, Map<String, Object>> pakistanMap = pakistanList.stream() Map<String, Map<String, Object>> pakistanMap = pakistanList.stream()
.collect(Collectors.toMap(item -> getValue(item, valueFields), item -> item,(existing, replacement) -> existing)); .collect(Collectors.toMap(item -> getValue(item, valueFields), item -> item, (existing, replacement) -> existing));
log.info("customerId = {} - tableName = {} - pakistanSet = {}", customerId, tableName, pakistanMap.keySet()); log.info("customerId = {} - tableName = {} - pakistanSet = {}", customerId, tableName, pakistanMap.keySet());
Map<String, Map<String, Object>> proMap = proList.stream() Map<String, Map<String, Object>> proMap = proList.stream()
.collect(Collectors.toMap(item -> getValue(item, valueFields), item -> item,(existing, replacement) -> existing)); .collect(Collectors.toMap(item -> getValue(item, valueFields), item -> item, (existing, replacement) -> existing));
log.info("customerId = {} - tableName = {} - proSet = {}", customerId, tableName, proMap.keySet()); log.info("customerId = {} - tableName = {} - proSet = {}", customerId, tableName, proMap.keySet());
// 合并所有 key // 合并所有 key
@@ -123,7 +213,6 @@ public class CompareService {
.filter(key -> !(pakistanMap.containsKey(key) && proMap.containsKey(key))) .filter(key -> !(pakistanMap.containsKey(key) && proMap.containsKey(key)))
.map(key -> pakistanMap.getOrDefault(key, proMap.get(key))) // 取出差异项 .map(key -> pakistanMap.getOrDefault(key, proMap.get(key))) // 取出差异项
.collect(Collectors.toList()); .collect(Collectors.toList());
log.info("customerId = {} - tableName = {} - differList = {}", customerId, tableName, diffList); log.info("customerId = {} - tableName = {} - differList = {}", customerId, tableName, diffList);
Set<Integer> differIds = diffList.stream() Set<Integer> differIds = diffList.stream()

View File

@@ -20,8 +20,8 @@ public abstract class TAG {
public static final List<String> VEHICLE_FIELDS = Arrays.asList("id", "name", "isDelete", "customerId"); public static final List<String> VEHICLE_FIELDS = Arrays.asList("id", "name", "isDelete", "customerId");
public static final List<String> DEVICE_FIELDS = Arrays.asList("id", "userPackageId", "isDelete", "synTime", "customerId"); public static final List<String> DEVICE_FIELDS = Arrays.asList("id", "userPackageId", "isDelete", "synTime", "customerId");
public static final List<String> BUSINESS_FIELDS = Arrays.asList("id", "name", "isDelete", "customerId"); public static final List<String> BUSINESS_FIELDS = Arrays.asList("id", "name", "isDelete", "customerId");
public static final List<String> DRIVER_FIELDS = Arrays.asList("id", "name", "isDelete", "email", "phone", "customerId"); public static final List<String> DRIVER_FIELDS = Arrays.asList("id", "name", "firstName", "lastName", "isDelete", "email", "phone", "customerId");
public static final List<String> VEHICLE_DEVICE_FIELDS = Arrays.asList("id", "vehicleId", "deviceId", "isDelete", "customerId"); public static final List<String> VEHICLE_DEVICE_FIELDS = Arrays.asList("id", "vehicleId", "deviceId", "isDelete", "customerId");
public static final List<String> DRIVER_VEHICLE_FIELDS = Arrays.asList("id", "driverId", "vehicleId", "isDelete", "customerId"); public static final List<String> DRIVER_VEHICLE_FIELDS = Arrays.asList("id", "driverId", "vehicleId", "isDelete", "customerId");
public static final List<String> BUSINESS_DRIVER_FIELDS = Arrays.asList("id", "businessId", "driverId", "isDelete", "customerId"); public static final List<String> BUSINESS_DRIVER_FIELDS = Arrays.asList("id", "businessId", "driverId", "isDelete", "customerId");
} }

View File

@@ -1,5 +1,6 @@
server: server:
port: 8889 port: 8889
address: 0.0.0.0
mqtt: mqtt:
inbound: inbound:
url: tcp://35.223.79.247:1883 url: tcp://35.223.79.247:1883

View File

@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- status内部日志级别monitorInterval每30秒检测一次配置文件是否有变化自动重载 -->
<Configuration status="WARN" monitorInterval="30">
<Properties>
<!-- 日志输出目录 -->
<Property name="LOG_HOME">logs</Property>
<!-- 通用日志输出格式 -->
<Property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Property>
<!-- 控制台日志格式(包含颜色) -->
<Property name="CONSOLE_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight{%-5level} %logger{36} - %msg%n</Property>
</Properties>
<Appenders>
<!-- 控制台输出 -->
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="${CONSOLE_PATTERN}" charset="UTF-8" alwaysWriteExceptions="false" disableAnsi="false"/>
</Console>
<!-- Info 日志文件,支持时间和大小滚动 -->
<RollingFile name="InfoFile"
fileName="${LOG_HOME}/app.log"
filePattern="logs/%d{yyyy-MM-dd}/app-%i.log.gz">
<PatternLayout pattern="${LOG_PATTERN}"/>
<Policies>
<!-- 超过指定大小就切割 -->
<SizeBasedTriggeringPolicy size="10 MB"/>
<!-- 每天切割一次 -->
<TimeBasedTriggeringPolicy/>
</Policies>
<!-- 最多保留30个历史文件 -->
<DefaultRolloverStrategy max="30"/>
<!-- 只接收 info 及以上,但不包含 errorerror 会被 error_file 接收) -->
<Filters>
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
</RollingFile>
<!-- Error 日志文件,按时间/大小滚动 -->
<RollingFile name="ErrorFile"
fileName="${LOG_HOME}/error.log"
filePattern="logs/%d{yyyy-MM-dd}/error-%i.log.gz">
<PatternLayout pattern="${LOG_PATTERN}"/>
<Policies>
<SizeBasedTriggeringPolicy size="10 MB"/>
<TimeBasedTriggeringPolicy/>
</Policies>
<DefaultRolloverStrategy max="30"/>
<!-- 只记录 error 级别日志 -->
<Filters>
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
</RollingFile>
</Appenders>
<Loggers>
<!-- 默认全局日志级别,设为 info低于 info 的日志不会打印) -->
<Root level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="InfoFile"/>
<AppenderRef ref="ErrorFile"/>
</Root>
</Loggers>
</Configuration>