feature: add log system
This commit is contained in:
@@ -1 +0,0 @@
|
||||
Error: Unable to access jarfile /home/zhangbiqiong/pro_eld_mqtt_compare/app/pro_eld_mqtt_compare-0.0.1-SNAPSHOT.jar
|
22
pom.xml
22
pom.xml
@@ -17,6 +17,12 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -44,16 +50,6 @@
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
<version>3.3.5</version>
|
||||
</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>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
@@ -79,6 +75,12 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-integration</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 替换默认日志系统为 Log4j2 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
@@ -9,7 +9,7 @@ import com.ctgu.pro_eld_mqtt_compare.utils.TAG;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
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.stereotype.Service;
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.stream.Collectors;
|
||||
* @Author Alex2
|
||||
* @Date 2025/7/4 10:34
|
||||
**/
|
||||
@Slf4j
|
||||
@Log4j2
|
||||
@Service
|
||||
public class CompareService {
|
||||
|
||||
|
@@ -15,4 +15,16 @@ mqtt:
|
||||
password: password123
|
||||
clientId: eld-mqtt
|
||||
topic: mqtt-anyfleet-to-eldapp
|
||||
qos: 0
|
||||
qos: 0
|
||||
logging:
|
||||
level:
|
||||
root: INFO # 应用程序的默认日志级别为 INFO
|
||||
com.ctgu: DEBUG # com.ctgu 包下的类的日志级别设置为 DEBUG
|
||||
org.apache.ibatis: INFO # MyBatis 日志级别设置为 INFO
|
||||
com.zaxxer.hikari: INFO # HikariCP 的日志级别设置为 INFO
|
||||
org.springframework.web.socket: DEBUG
|
||||
org.springframework.web.socket.server.support: DEBUG
|
||||
org:
|
||||
springframework:
|
||||
integration: DEBUG
|
||||
messaging: DEBUG
|
74
src/main/resources/log4j2.xml
Normal file
74
src/main/resources/log4j2.xml
Normal file
@@ -0,0 +1,74 @@
|
||||
<?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>
|
||||
</Properties>
|
||||
|
||||
<Appenders>
|
||||
<!-- 控制台输出 -->
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
</Console>
|
||||
|
||||
<!-- Info 日志文件,支持时间和大小滚动 -->
|
||||
<RollingFile name="InfoFile" fileName="${LOG_HOME}/app-info.log"
|
||||
filePattern="${LOG_HOME}/app-info-%d{yyyy-MM-dd}-%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
|
||||
<Policies>
|
||||
<!-- 超过指定大小就切割 -->
|
||||
<SizeBasedTriggeringPolicy size="10 MB"/>
|
||||
<!-- 每天切割一次 -->
|
||||
<TimeBasedTriggeringPolicy/>
|
||||
</Policies>
|
||||
|
||||
<!-- 最多保留15个历史文件 -->
|
||||
<DefaultRolloverStrategy max="15"/>
|
||||
|
||||
<!-- 只接收 info 及以上,但不包含 error(error 会被 error_file 接收) -->
|
||||
<Filters>
|
||||
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||
</Filters>
|
||||
</RollingFile>
|
||||
|
||||
<!-- Error 日志文件,按时间/大小滚动 -->
|
||||
<RollingFile name="ErrorFile" fileName="${LOG_HOME}/app-error.log"
|
||||
filePattern="${LOG_HOME}/app-error-%d{yyyy-MM-dd}-%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
|
||||
<Policies>
|
||||
<SizeBasedTriggeringPolicy size="10 MB"/>
|
||||
<TimeBasedTriggeringPolicy/>
|
||||
</Policies>
|
||||
|
||||
<DefaultRolloverStrategy max="15"/>
|
||||
|
||||
<!-- 只记录 error 级别日志 -->
|
||||
<Filters>
|
||||
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||
</Filters>
|
||||
</RollingFile>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<!-- com.ctgu 包下的类使用 debug 级别 -->
|
||||
<Logger name="com.ctgu.log" level="debug" additivity="false">
|
||||
<!-- 不向上(root)传递,防止重复打印 -->
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="InfoFile"/>
|
||||
<AppenderRef ref="ErrorFile"/>
|
||||
</Logger>
|
||||
|
||||
<!-- 默认全局日志级别,设为 info(低于 info 的日志不会打印) -->
|
||||
<Root level="info">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="InfoFile"/>
|
||||
<AppenderRef ref="ErrorFile"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
Reference in New Issue
Block a user