From 692df153a5380cafcdf1bc9bae159fe7940c06a2 Mon Sep 17 00:00:00 2001 From: gitee-bot Date: Mon, 29 Sep 2025 08:00:18 +0000 Subject: [PATCH] Add README.md --- README.en.md | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 README.en.md create mode 100644 README.md diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..e96e147 --- /dev/null +++ b/README.en.md @@ -0,0 +1,92 @@ +# lzh-21-log-spring-boot-starter + +A Spring Boot Starter designed to simplify logging, providing functionalities such as log aspects, trace filters, and MDC adapters. + +## Features + +- **Log Aspect (LogAdvice)**: Implements method-level logging through AOP. +- **Trace Filter (WebTraceFilter)**: Generates a unique trace ID for each request. +- **MDC Adapter (TtlMDCAdapter)**: Supports log tracing across thread contexts. +- **Log Utility (MDCTraceUtil)**: Provides generation and management of trace IDs and span IDs. + +## Usage + +### 1. Add Dependency + +Add the Starter dependency in your `pom.xml`: + +```xml + + com.lzh + lzh-21-log-spring-boot-starter + 1.0.0 + +``` + +### 2. Enable Logging Functionality + +Add the `@EnableAspectJAutoProxy` annotation to the main class of your Spring Boot application to enable AOP: + +```java +@SpringBootApplication +@EnableAspectJAutoProxy +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} +``` + +### 3. Use Logging Annotation + +Add the `@Log` annotation to methods where logging is needed: + +```java +@RestController +public class ExampleController { + + @Log + @GetMapping("/example") + public String example() { + return "Hello, World!"; + } +} +``` + +## Configuration + +### Log Configuration + +Configure the log output format and level in `application.yml` or `application.properties`: + +```yaml +logging: + level: + com.lzh.log: DEBUG +``` + +### Custom Trace ID Generation + +You can customize the trace ID generation logic by overriding the `createTraceId()` method in `MDCTraceUtil`. + +## Build and Deployment + +### Build the Project + +```bash +mvn clean install +``` + +### Deploy to Repository + +```bash +mvn deploy +``` + +## Contributions + +Pull requests and suggestions are welcome. Please ensure consistent code style and provide clear commit messages. + +## License + +This project is licensed under the MIT License. For details, please refer to the [LICENSE](LICENSE) file. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0c41878 --- /dev/null +++ b/README.md @@ -0,0 +1,92 @@ +# lzh-21-log-spring-boot-starter + +一个用于简化日志记录的 Spring Boot Starter,提供日志切面、追踪过滤器和 MDC 适配器等功能。 + +## 特性 + +- **日志切面(LogAdvice)**:通过 AOP 实现方法级别的日志记录。 +- **追踪过滤器(WebTraceFilter)**:为每个请求生成唯一的追踪 ID。 +- **MDC 适配器(TtlMDCAdapter)**:支持线程上下文的日志追踪。 +- **日志工具类(MDCTraceUtil)**:提供追踪 ID 和 Span ID 的生成与管理。 + +## 使用方法 + +### 1. 添加依赖 + +在 `pom.xml` 中添加该 Starter 的依赖: + +```xml + + com.lzh + lzh-21-log-spring-boot-starter + 1.0.0 + +``` + +### 2. 启用日志功能 + +在 Spring Boot 应用的主类上添加 `@EnableAspectJAutoProxy` 注解以启用 AOP: + +```java +@SpringBootApplication +@EnableAspectJAutoProxy +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} +``` + +### 3. 使用日志注解 + +在需要记录日志的方法上添加 `@Log` 注解: + +```java +@RestController +public class ExampleController { + + @Log + @GetMapping("/example") + public String example() { + return "Hello, World!"; + } +} +``` + +## 配置 + +### 日志配置 + +在 `application.yml` 或 `application.properties` 中配置日志输出格式和级别: + +```yaml +logging: + level: + com.lzh.log: DEBUG +``` + +### 自定义追踪 ID 生成 + +可以通过自定义 `MDCTraceUtil` 中的 `createTraceId()` 方法来实现自己的追踪 ID 生成逻辑。 + +## 构建与发布 + +### 构建项目 + +```bash +mvn clean install +``` + +### 发布到仓库 + +```bash +mvn deploy +``` + +## 贡献 + +欢迎提交 Pull Request 和建议。请确保代码风格一致,并提供清晰的提交信息。 + +## 许可证 + +该项目使用 MIT 许可证。详情请查看 [LICENSE](LICENSE) 文件。 \ No newline at end of file -- Gitee