优化RequestInfoProvider
This commit is contained in:
parent
c4e421050e
commit
27076012a7
@ -31,13 +31,12 @@ public abstract class BaseProvider implements JsonProvider<ILoggingEvent> {
|
||||
}
|
||||
|
||||
// 写入公共字段
|
||||
protected void writeCommonField(RuntimeContext runtimeContext, JsonGenerator gen, String logType, Object logData) throws IOException {
|
||||
protected void writeCommonField(RuntimeContext runtimeContext, JsonGenerator gen, Object logData) throws IOException {
|
||||
gen.writeNumberField(RecordField.TIMESTAMP, System.currentTimeMillis()); // 记录日志的时间
|
||||
gen.writeStringField(RecordField.REQUEST_ID, runtimeContext.getRequestId());
|
||||
gen.writeStringField(RecordField.TRACE_ID, runtimeContext.getTraceId());
|
||||
gen.writeStringField(RecordField.SERVER_IP, runtimeContext.getServerIp());
|
||||
gen.writeStringField(RecordField.SERVER_HOSTNAME, runtimeContext.getServerHostname());
|
||||
gen.writeStringField(RecordField.LOGGER_TYPE, logType);
|
||||
gen.writeStringField(RecordField.REQUEST_METHOD, runtimeContext.getRequestInfo().getRequestMethod());
|
||||
gen.writeStringField(RecordField.REQUEST_URI, runtimeContext.getRequestInfo().getRequestUri());
|
||||
gen.writeStringField(RecordField.REQUEST_CLIENT_IP, runtimeContext.getRequestInfo().getClientIp());
|
||||
|
@ -17,6 +17,6 @@ public class RequestInfoLogProvider extends BaseProvider {
|
||||
return;
|
||||
}
|
||||
// 请求输入日志
|
||||
writeCommonField(runtimeContext, gen, LogTypeEnum.REQUEST_INPUT.getLogType(), runtimeContext.getRequestInfo());
|
||||
writeCommonField(runtimeContext, gen, runtimeContext.getRequestInfo());
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
package cn.zhangdeman.logger;
|
||||
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import cn.zhangdeman.consts.RecordField;
|
||||
import cn.zhangdeman.context.RuntimeContext;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
// 记录请求信息
|
||||
public class ResponseInfoLogProvider extends BaseProvider {
|
||||
@Override
|
||||
public void writeTo(JsonGenerator gen, ILoggingEvent event) throws IOException {
|
||||
RuntimeContext runtimeContext = getCurrentRequest();
|
||||
if (null == runtimeContext) {
|
||||
// 非 http 请求不应该用到这个provider
|
||||
return;
|
||||
}
|
||||
// 请求输入日志
|
||||
writeCommonField(runtimeContext, gen, LogTypeEnum.REQUEST_OUTPUT.getLogType(), runtimeContext.getResponse().toString());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user