修改日志保存日期
This commit is contained in:
parent
1bd78fc291
commit
ecbc9045a7
@ -81,15 +81,10 @@ public class LogMdcConfiguration {
|
||||
|
||||
if(ctx.hasKey(Log4Constans.PRINT_LOG_ID)){
|
||||
MDC.put(Log4Constans.PRINT_LOG_ID, ctx.get(Log4Constans.PRINT_LOG_ID));
|
||||
//String requestId = WebFluxSkyWalkingTraceContext.traceId();
|
||||
//Tracer.createLocalSpan(Log4Constans.PRINT_LOG_ID);
|
||||
|
||||
// return;
|
||||
}
|
||||
WebFluxSkyWalkingOperators.continueTracing(ctx, () ->{
|
||||
coreSubscriber.onNext(t);
|
||||
});
|
||||
//coreSubscriber.onNext(t);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -42,11 +42,11 @@ import java.nio.charset.StandardCharsets;
|
||||
public class LogWebFilter implements WebFilter {
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
//Tracer.stopSpan();
|
||||
//Tracer.createEntrySpan(Log4Constans.PRINT_LOG_ID, null);
|
||||
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
String requestId = WebFluxSkyWalkingTraceContext.traceId(exchange);
|
||||
String requestId = WebFluxSkyWalkingTraceContext.segmentId(exchange);
|
||||
log.info("获取到的traceId:{}", requestId);
|
||||
//String pid = WebFluxSkyWalkingTraceContext.getCorrelation(exchange, Log4Constans.PRINT_LOG_ID).get();
|
||||
//log.info("获取到的pid:{}", pid);
|
||||
@ -87,41 +87,52 @@ public class LogWebFilter implements WebFilter {
|
||||
return contextTmp;
|
||||
|
||||
}).doFinally(signalType -> {
|
||||
long endTime = System.currentTimeMillis();
|
||||
MDC.put(Log4Constans.PRINT_LOG_ID, tracId);
|
||||
log.info("api end time:{}, total time:{}", endTime, endTime - startTime);
|
||||
//Tracer.stopSpan();
|
||||
MDC.remove(Log4Constans.PRINT_LOG_ID);
|
||||
}).contextWrite(ctx -> {
|
||||
Context contextTmp = ctx.put(Log4Constans.PRINT_LOG_ID, tracId);
|
||||
return contextTmp;
|
||||
WebFluxSkyWalkingOperators.continueTracing(newEx, () -> {
|
||||
long endTime = System.currentTimeMillis();
|
||||
MDC.put(Log4Constans.PRINT_LOG_ID, tracId);
|
||||
log.info("api end time:{}, total time:{}", endTime, endTime - startTime);
|
||||
MDC.remove(Log4Constans.PRINT_LOG_ID);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private ServerHttpRequest getRequest(ServerWebExchange exchange){
|
||||
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
return new ServerHttpRequestDecorator(request){
|
||||
@Override
|
||||
public Flux<DataBuffer> getBody() {
|
||||
Flux<DataBuffer> body = this.getDelegate().getBody();
|
||||
return body.map(dataBuffer -> {
|
||||
if(!request.getMethod().equals(HttpMethod.GET) && !request.getMethod().equals(HttpMethod.DELETE)) {
|
||||
log.info("request:{}", dataBuffer.toString(StandardCharsets.UTF_8));
|
||||
}
|
||||
return dataBuffer;
|
||||
});
|
||||
}
|
||||
return WebFluxSkyWalkingOperators.continueTracing(exchange, () -> {
|
||||
return new ServerHttpRequestDecorator(request) {
|
||||
@Override
|
||||
public Flux<DataBuffer> getBody() {
|
||||
Flux<DataBuffer> body = this.getDelegate().getBody();
|
||||
return body.map(dataBuffer -> {
|
||||
if (/*!request.getMethod().equals(HttpMethod.GET) && */!request.getMethod().equals(HttpMethod.DELETE)) {
|
||||
log.info("request:{}", dataBuffer.toString(StandardCharsets.UTF_8));
|
||||
}
|
||||
return dataBuffer;
|
||||
});
|
||||
}
|
||||
/*
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.putAll(super.getHeaders());
|
||||
//httpHeaders.set("sw8", "customerIp");//sklwaking传过来的
|
||||
//httpHeaders.set(Log4Constans.HEADER_TRACE_ID, tracId);
|
||||
log.info("获取头信息");
|
||||
return httpHeaders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
log.info("获取方法");
|
||||
return super.getMethodValue();
|
||||
};
|
||||
*/
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
/*@Override
|
||||
public HttpHeaders getHeaders(){
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.putAll(super.getHeaders());
|
||||
httpHeaders.set("sw8", "customerIp");//sklwaking传过来的
|
||||
//httpHeaders.set(Log4Constans.HEADER_TRACE_ID, tracId);
|
||||
return httpHeaders;
|
||||
}*/
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/wran.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<fileNamePattern>${log.path}/warn.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/wran.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<fileNamePattern>${log.path}/warn.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user