Introducing TLog: Lightweight Log Tagging for Microservice Tracing in Spring Boot
TLog provides a non‑intrusive, zero‑storage solution for tracing logs across microservices by automatically tagging log entries with a TraceId, supporting major Java logging frameworks and RPC libraries, and can be integrated into a Spring Boot project in just a few minutes.
TLog: Solving Log Tracing Pain Points
With the rise of micro‑service architectures, many companies split their systems into numerous services, making it difficult to locate logs for a specific request across the whole call chain. Traditional distributed‑tracing tools such as SkyWalking or Pinpoint require additional infrastructure, storage, and operational effort.
TLog offers a simpler approach: it does not collect or store logs, but automatically tags each log line with a TraceId that propagates through the entire micro‑service chain, providing upstream and downstream node information without extra storage costs.
Project Features
Lightweight log tagging for micro‑service tracing.
Non‑intrusive design; can be integrated within 10 minutes.
Supports Log4j, Log4j2, and Logback with automatic detection and adaptation.
Compatible with Dubbo, Dubbox, and Spring Cloud RPC frameworks.
Customizable tag templates and multiple system‑level tags.
Provides a spanId to indicate the position of the current call in the call‑tree.
Method‑level custom tag injection.
Native support for asynchronous thread tracing.
Almost no performance overhead.
Quick Start
Dependency
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>tlog-all-spring-boot-starter</artifactId>
<version>1.1.0</version>
</dependency>The JAR is already published to Maven Central, so you can add the above dependency directly.
Log Framework Adaptation
Add a single line in your Spring Boot main class to let TLog automatically detect and enhance the logging framework you use.
@SpringBootApplication
public class Runner {
static { AspectLogEnhance.enhance(); } // enable log enhancement via Javassist
public static void main(String[] args) {
SpringApplication.run(Runner.class, args);
}
}Note: the static block must run before the target logging classes are loaded; therefore, do not define a logger field in the same class.
RPC Framework Adaptation
When running under Spring Boot, TLog automatically detects the RPC framework (Dubbo, Dubbox, or Spring Cloud) and applies the necessary enhancements.
Final Effect
After the two steps above, the Spring Boot application is ready for TLog. The following examples show log output for a Dubbo + Logback consumer and provider.
Consumer code (Dubbo + Log4j example)
2020-09-16 18:12:56,748 [WARN] [TLOG] Re‑generated traceId[7161457983341056] >> com.yomahub.tlog.web.TLogWebInterceptor:39
2020-09-16 18:12:56,763 [INFO] <7161457983341056> logback-dubbox-consumer:invoke method sayHello,name=jack >> com.yomahub.tlog.example.dubbox.controller.DemoController:22
2020-09-16 18:12:56,763 [INFO] <7161457983341056> test log aaaa >> com.yomahub.tlog.example.dubbox.controller.DemoController:23
2020-09-16 18:12:56,763 [INFO] <7161457983341056> test log bbbb >> com.yomahub.tlog.example.dubbox.controller.DemoController:24Provider code
2020-09-16 18:12:56,854 [INFO] <7161457983341056> logback-dubbox-provider:invoke method sayHello,name=jack >> com.yomahub.tlog.example.dubbo.service.impl.DemoServiceImpl:15
2020-09-16 18:12:56,854 [INFO] <7161457983341056> test log cccc >> com.yomahub.tlog.example.dubbo.service.impl.DemoServiceImpl:16
2020-09-16 18:12:56,854 [INFO] <7161457983341056> test log dddd >> com.yomahub.tlog.example.dubbo.service.impl.DemoServiceImpl:17Each request now carries a globally unique TraceId that appears in every log line, making it easy to follow a request across services.
Project URL
Official site: http://bryan31.gitee.io/tlog
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.