修复请求日志记录的BUG
This commit is contained in:
parent
27076012a7
commit
d20294ae98
@ -45,6 +45,11 @@ public abstract class BaseProvider implements JsonProvider<ILoggingEvent> {
|
||||
gen.writeObjectField(RecordField.CONTEXT_DATA,logData); // 除了公共字段值外的其他数据, 统一放在logData中
|
||||
}
|
||||
|
||||
// 获取日志名称
|
||||
protected String getLoggerType(ILoggingEvent loggingEvent) {
|
||||
return loggingEvent.getLoggerName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareForDeferredProcessing(ILoggingEvent iLoggingEvent) {
|
||||
|
||||
|
@ -6,6 +6,7 @@ import lombok.Getter;
|
||||
public enum LogTypeEnum {
|
||||
REQUEST_INPUT("input", "请求输入信息"),
|
||||
REQUEST_OUTPUT("output", "请求响应信息"),
|
||||
REQUEST_BUSINESS("business", "请求业务逻辑日志"),
|
||||
DATABASE_RECORD("database", "数据库日志记录"),
|
||||
CACHE_RECORD("cache", "缓存日志记录"),
|
||||
API_RECORD("api", "第三方接口请求"),
|
||||
|
@ -13,6 +13,10 @@ public class LoggerInstance {
|
||||
* 请求响应日志实例
|
||||
*/
|
||||
public static final Logger REQUEST_OUTPUT_LOGGER = LoggerFactory.getLogger(LogTypeEnum.REQUEST_OUTPUT.getLogType());
|
||||
/**
|
||||
* 请求业务逻辑日志实例记录
|
||||
*/
|
||||
public static final Logger REQUEST_BUSINESS_LOGGER = LoggerFactory.getLogger(LogTypeEnum.REQUEST_BUSINESS.getLogType());
|
||||
/**
|
||||
* 数据库sql记录
|
||||
*/
|
||||
|
@ -6,6 +6,7 @@ import cn.zhangdeman.context.RuntimeContext;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
// 记录请求信息
|
||||
public class RequestInfoLogProvider extends BaseProvider {
|
||||
@ -16,7 +17,14 @@ public class RequestInfoLogProvider extends BaseProvider {
|
||||
// 非 http 请求不应该用到这个provider
|
||||
return;
|
||||
}
|
||||
if (Objects.equals(getLoggerType(event), LogTypeEnum.REQUEST_INPUT.getLogType())) {
|
||||
// 请求输入日志
|
||||
writeCommonField(runtimeContext, gen, runtimeContext.getRequestInfo());
|
||||
} else if (Objects.equals(getLoggerType(event), LogTypeEnum.REQUEST_OUTPUT.getLogType())) {
|
||||
// 请求输出日志
|
||||
writeCommonField(runtimeContext, gen, runtimeContext.getResponse());
|
||||
} else {
|
||||
System.out.println("请求信息记录器需要将日志的类型设置为: input(请求记录) 或 output(响应记录)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user