### SkyWalking TraceId Integration Example
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Java example demonstrating how to get SkyWalking's trace ID within an interceptor.
```java
import org.apache.skywalking.apm.toolkit.trace.TraceContext;
@Component
public class Interceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String traceId = TraceContext.traceId();//核心是此处获取skywalking的traceId
TraceId.logTraceID.set(traceId);
return true;
}
}
```
--------------------------------
### PlumeLog Server Maven Deploy Configuration
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Example of setting the distribution repository URL in the pom.xml for Maven deployment.
```xml
UTF-8
http://172.16.249.94:4000
```
--------------------------------
### MDC Usage for Extended Fields
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Example of using MDC (Mapped Diagnostic Context) to add custom fields like order ID and user ID to logs.
```java
MDC.put("orderid","1");
MDC.put("userid","4");
logger.info("扩展字段");
```
--------------------------------
### Static File Access Configuration (application.properties)
Source: https://github.com/fayechenlong/plumelog/blob/master/plumelog-lite/README.md
Configure static file access patterns and locations in application.properties if PlumeLog pages appear blank.
```properties
spring.mvc.static-path-pattern=/**
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
```
--------------------------------
### Static File Access Configuration (WebMvcConfigurerAdapter)
Source: https://github.com/fayechenlong/plumelog/blob/master/plumelog-lite/README.md
If your project has interceptors, configure static file access within the interceptor to avoid conflicts.
```java
import com.plumelog.core.PlumeLogTraceIdInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class TraceIdInterceptorsConfig extends WebMvcConfigurerAdapter{
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"};
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//就是这句addResourceLocations,加上静态文件访问路径
registry.addResourceHandler("/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new PlumeLogTraceIdInterceptor());
super.addInterceptors(registry);
}
}
```
--------------------------------
### Maven Dependency for plumelog-lite Spring Boot Starter
Source: https://github.com/fayechenlong/plumelog/blob/master/plumelog-lite/README.md
Use this starter for easier integration with Spring Boot, avoiding manual configuration of scan paths and static file paths.
```xml
com.plumelog
plumelog-lite-spring-boot-starter
3.5.3
```
--------------------------------
### Handling LockObtainFailedException (Spring Cloud Alibaba)
Source: https://github.com/fayechenlong/plumelog/blob/master/plumelog-lite/README.md
For Spring Cloud Alibaba projects, set the system property 'spring.cloud.bootstrap.enabled' to 'false' in your main application class to resolve the LockObtainFailedException.
```java
public static void main(String[] args) {
System.setProperty("spring.cloud.bootstrap.enabled", "false");
SpringApplication.run(LogServerStart.class, args);
}
```
--------------------------------
### Logback Configuration (Redis)
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Configure logback to use RedisAppender for PlumeLog.
```xml
plumelog
172.16.249.72:6379
123456
plumelog
172.16.247.143:9092,172.16.247.60:9092,172.16.247.64:9092
worker
localhost:8891
```
--------------------------------
### Runnable/Callable with ThreadLocal Propagation
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Wrapping Runnable and Callable with TtlRunnable/TtlCallable to propagate ThreadLocal values, demonstrated with TraceId.
```java
private static ThreadPoolExecutor threadPoolExecutor=ThreadPoolUtil.getPool(4,8,5000);
threadPoolExecutor.execute(TtlRunnable.get(()->{
TraceId.logTraceID.get();
logger.info("tankSay =》我是子线程的日志!{}",TraceId.logTraceID.get());
}));
```
--------------------------------
### TraceId Filter Configuration (Non-SpringBoot/Cloud)
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Java configuration for adding a TraceId filter in traditional projects.
```java
import com.plumelog.core.TraceIdFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.Filter;
@Configuration
public class PlumeLogilterConfig {
@Bean
public FilterRegistrationBean filterRegistrationBean1() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(initCustomFilter());
filterRegistrationBean.addUrlPatterns("/*");
filterRegistrationBean.setOrder(Integer.MIN_VALUE);
return filterRegistrationBean;
}
@Bean
public Filter initCustomFilter() {
return new TraceIdFilter();
}
}
```
--------------------------------
### Logback Configuration for PlumeLog
Source: https://github.com/fayechenlong/plumelog/blob/master/plumelog-lite/README.md
Configure your logback.xml to use the LiteAppender for PlumeLog, specifying app name, log path, and retention days.
```xml
plumelog
/plumelog/lite
30
```
--------------------------------
### Log4j Configuration (Lite)
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Configure log4j to use LiteAppender for PlumeLog.
```properties
#lite模式
log4j.appender.L=com.plumelog.log4j.appender.LiteAppender
log4j.appender.L.appName=plumelog
log4j.appender.L.env=${spring.profiles.active}
log4j.appender.L.plumelogHost=localhost:8891
```
--------------------------------
### TraceId Setting for Non-Web Projects
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Code snippet to set TraceId at the beginning of execution in non-web projects like scheduled tasks.
```java
TraceId.set();
```
--------------------------------
### Logback Dependency
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Add the plumelog-logback dependency to your project.
```xml
com.plumelog
plumelog-logback
3.5.3
```
--------------------------------
### Servlet web.xml TraceIdFilter Configuration
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
XML configuration for adding TraceIdFilter in web.xml for servlet-based applications.
```xml
TraceIdFilter
com.plumelog.core.TraceIdFilter
TraceIdFilter
/*
```
--------------------------------
### ExecutorService with ThreadLocal Propagation
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Using TtlExecutors to wrap an ExecutorService for automatic propagation of ThreadLocal values across threads.
```java
private static ExecutorService executorService=TtlExecutors.getTtlExecutorService(
new ThreadPoolExecutor(8,8,0L,TimeUnit.MILLISECONDS,new LinkedBlockingQueue()));
//省去每次Runnable和Callable传入线程池时的修饰,这个逻辑可以在线程池中完成
executorService.execute(()->{
logger.info("子线程日志展示");
});
```
--------------------------------
### TraceId Interceptor Configuration (Non-SpringBoot/Cloud)
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Java configuration for adding a TraceId interceptor in traditional projects.
```java
import com.plumelog.core.PlumeLogTraceIdInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class TraceIdInterceptorsConfig extends WebMvcConfigurerAdapter {
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"};
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//plumelog-lite的用户注意,拦截器会覆盖静态文件访问路径,导致不能访问查询页面,所以这边需要用addResourceLocations设置下静态文件访问路径,其他的用户可以不用管
registry.addResourceHandler("/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new PlumeLogTraceIdInterceptor());
super.addInterceptors(registry);
}
}
```
--------------------------------
### Log4j Configuration (Kafka)
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Configure log4j to use KafkaAppender for PlumeLog.
```properties
log4j.rootLogger=INFO,stdout,L
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} [%c.%t]%n%m%n
#kafka做为中间件
log4j.appender.L=com.plumelog.log4j.appender.KafkaAppender
#appName系统的名称(自己定义就好)
log4j.appender.L.appName=plumelog
log4j.appender.L.env=${spring.profiles.active}
log4j.appender.L.kafkaHosts=172.16.247.143:9092,172.16.247.60:9092,172.16.247.64:9092
```
--------------------------------
### Log4j Configuration (Redis)
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Configure log4j to use RedisAppender for PlumeLog.
```properties
#redis做为中间件
log4j.appender.L=com.plumelog.log4j.appender.RedisAppender
log4j.appender.L.appName=plumelog
log4j.appender.L.env=${spring.profiles.active}
log4j.appender.L.redisHost=172.16.249.72:6379
#redis没有密码这一项为空或者不需要
#log4j.appender.L.redisAuth=123456
```
--------------------------------
### Spring Boot Application Class Configuration
Source: https://github.com/fayechenlong/plumelog/blob/master/plumelog-lite/README.md
Add the scan path for PlumeLog in your Spring Boot application class. Ensure your project's scan paths are also included.
```java
@ComponentScan("com.plumelog")
```
--------------------------------
### SkyWalking TraceId Dependency
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Dependency required for integrating with SkyWalking for trace ID retrieval.
```xml
org.apache.skywalking
apm-toolkit-trace
6.5.0
```
--------------------------------
### Spring Boot/Cloud Sleuth Dependency
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Dependency required for Spring Boot and Spring Cloud projects to generate Trace IDs.
```xml
org.springframework.cloud
spring-cloud-starter-sleuth
2.2.7.RELEASE
```
--------------------------------
### Spring Boot Admin Client Dependency
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Maven dependencies required to integrate Spring Boot Admin client for dynamic log level modification.
```xml
de.codecentric
spring-boot-admin-starter-client
2.1.6
org.springframework.boot
spring-boot-starter-actuator
```
--------------------------------
### Maven Dependency for plumelog-lite
Source: https://github.com/fayechenlong/plumelog/blob/master/plumelog-lite/README.md
Add this dependency to your project to include plumelog-lite.
```xml
com.plumelog
plumelog-lite
3.5.3
```
--------------------------------
### Spring Boot Application Properties for Admin
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Application properties to configure the Spring Boot Admin client URL and expose management endpoints.
```properties
#plumelog的地址加后缀admin
spring.boot.admin.client.url=http://localhost:8891/admin
management.endpoints.web.exposure.include=*
```
--------------------------------
### Log4j Dependency
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Add the plumelog-log4j dependency to your project.
```xml
com.plumelog
plumelog-log4j
3.5.3
```
--------------------------------
### Non-Java Project API Integration
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
JSON structure for sending logs to PlumeLog server via API for non-Java projects.
```json
[
{
"appName":"应用名称",
"serverName":"服务器IP地址",
"dtTime":"时间戳的时间格式",
"traceId":"自己生成的traceid",
"content":"日志内容",
"logLevel":"日志等级 INFO ERROR WARN ERROR大写",
"className":"产生日志的类名",
"method":"产生日志的方法",
"logType":"1",
"dateTime":"2020-12-25 10:10:10"
},{
"appName":"应用名称",
"serverName":"服务器IP地址",
"dtTime":"时间戳的时间格式",
"traceId":"自己生成的traceid",
"content":"日志内容",
"logLevel":"日志等级 INFO ERROR WARN ERROR大写",
"className":"产生日志的类名",
"method":"产生日志的方法",
"logType":"1",
"dateTime":"2020-12-25 10:10:10"
}....
]
```
--------------------------------
### WebFlux TraceId Filter
Source: https://github.com/fayechenlong/plumelog/blob/master/FASTSTART.md
Bean definition for WebFlux TraceId filter.
```java
@Bean
public WebFluxTraceIdFilter initCustomFilter(){
return new WebFluxTraceIdFilter();
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.