# lzh-1.8-log-spring-boot-starter **Repository Path**: coding_13/lzh-1.8-log-spring-boot-starter ## Basic Information - **Project Name**: lzh-1.8-log-spring-boot-starter - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-08-10 - **Last Updated**: 2025-08-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # lzh-1.8-log-spring-boot-starter This is a Spring Boot Starter module designed to automatically integrate logging functionality into projects. It supports features such as log aspects, MDC context management, and distributed tracing, making it suitable for log tracing scenarios in microservices architecture. ## Key Features - **Log Aspect (LogAdvice)**: Implements method-level logging through AOP, supporting log output control via the `@Log` annotation. - **Distributed Tracing Support (MDCTraceUtil)**: Supports generation and transmission of `traceId` and `spanId` for request chain tracing. - **MDC Context Adapter (TtlMDCAdapter)**: Uses `TransmittableThreadLocal` to propagate MDC context within thread pools, suitable for asynchronous scenarios. - **Web Request Filter (WebTraceFilter)**: Automatically injects trace information at the beginning of Web requests. - **Auto Configuration (LogAutoConfigure)**: Automatically registers relevant components for out-of-the-box usability. ## How to Use 1. Include the module as a dependency in your Spring Boot project: ```xml com.lzh lzh-1.8-log-spring-boot-starter 1.0.0 ``` 2. No additional configuration is required on the Spring Boot main class; the functionality is enabled automatically. 3. Add the `@Log` annotation to methods or classes where logging is needed: ```java @RestController public class ExampleController { @Log @GetMapping("/example") public String example() { return "Hello, World!"; } } ``` 4. The log will automatically include `traceId` and `spanId`, facilitating chain tracing. ## Configuration Instructions - The log format can be customized in `logback-spring.xml`, and it is recommended to include `%X{traceId}` and `%X{spanId}`. - Log levels and filter rules can be configured through `application.properties` or `application.yml`. ## Module Structure - `LogAutoConfigure`: Auto configuration class responsible for registering components. - `LogAdvice`: AOP aspect for implementing method-level logging. - `Log`: Annotation used to mark methods or classes for logging. - `MDCTraceUtil`: Utility class for generating and managing `traceId` and `spanId`. - `TtlMDCAdapter`: Thread-safe MDC implementation supporting asynchronous scenarios. - `TtlMDCAdapterInitializer`: Initializer for the MDC adapter. - `WebTraceFilter`: Web request filter for injecting trace information. ## License This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.