feat(common): add API operation logging with AOP and trace ID tracking
This commit is contained in:
@@ -2,8 +2,10 @@ package com.hanserwei.web;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan({"com.hanserwei.*"})
|
||||
public class WeblogWebApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WeblogWebApplication.class, args);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.hanserwei.web.controller;
|
||||
|
||||
import com.hanserwei.common.aspect.ApiOperationLog;
|
||||
import com.hanserwei.web.model.User;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
public class TestController {
|
||||
|
||||
@PostMapping("/test")
|
||||
@ApiOperationLog(description = "测试接口")
|
||||
public User test(@RequestBody User user) {
|
||||
// 返参
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
11
weblog-web/src/main/java/com/hanserwei/web/model/User.java
Normal file
11
weblog-web/src/main/java/com/hanserwei/web/model/User.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.hanserwei.web.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class User {
|
||||
// 用户名
|
||||
private String username;
|
||||
// 性别
|
||||
private Integer sex;
|
||||
}
|
||||
@@ -7,7 +7,8 @@
|
||||
<property scope="context" name="appName" value="weblog"/>
|
||||
<!-- 自定义日志输出路径,以及日志名称前缀 -->
|
||||
<property name="LOG_FILE" value="/app/weblog/logs/${appName}.%d{yyyy-MM-dd}"/>
|
||||
<property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n"/>
|
||||
<property name="FILE_LOG_PATTERN"
|
||||
value="[TraceId: %X{traceId}] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n"/>
|
||||
<!--<property name="CONSOLE_LOG_PATTERN" value="${FILE_LOG_PATTERN}"/>-->
|
||||
|
||||
<!-- 按照每天生成日志文件 -->
|
||||
@@ -31,7 +32,7 @@
|
||||
<!-- dev 环境(仅输出到控制台) -->
|
||||
<springProfile name="dev">
|
||||
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
|
||||
<root level="info">
|
||||
<root level="INFO">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
|
||||
Reference in New Issue
Block a user