服务端全局访问日志调整。
This commit is contained in:
+1
@@ -64,6 +64,7 @@ public class DBInitialize implements EventListener<AppLoadEndEvent> {
|
||||
@Override
|
||||
public void onEvent(AppLoadEndEvent appLoadEndEvent) throws Throwable {
|
||||
// TODO 该事件有50%的概率不触发
|
||||
System.out.println("11");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ public class BaseAuthInterceptor implements RouterInterceptor {
|
||||
|
||||
@Override
|
||||
public Object postResult(Context ctx, Object result) throws Throwable {
|
||||
// SystemContextHolder.remove();
|
||||
SystemContextHolder.remove();
|
||||
if (result instanceof ResponseBody) {
|
||||
return result;
|
||||
}
|
||||
|
||||
+11
-33
@@ -1,12 +1,8 @@
|
||||
package fun.asgc.neutrino.proxy.server.base.rest.interceptor;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.SystemContext;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.SystemContextHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.boot.jlhttp.HTTPServer;
|
||||
import org.noear.solon.boot.jlhttp.JlHttpContext;
|
||||
import org.noear.solon.core.handle.Action;
|
||||
import org.noear.solon.core.handle.Context;
|
||||
import org.noear.solon.core.handle.Handler;
|
||||
@@ -28,37 +24,19 @@ public class VisitLogInterceptor implements RouterInterceptor {
|
||||
chain.doIntercept(ctx, mainHandler);
|
||||
return;
|
||||
}
|
||||
SystemContext systemContext = SystemContextHolder.getContext();
|
||||
if (null == systemContext) {
|
||||
chain.doIntercept(ctx, mainHandler);
|
||||
return;
|
||||
}
|
||||
Action action = (Action) mainHandler;
|
||||
systemContext.setAction(action);
|
||||
systemContext.setReceiveTime(new Date());
|
||||
|
||||
Date startTime = new Date();
|
||||
|
||||
chain.doIntercept(ctx, mainHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postResult(Context ctx, Object result) throws Throwable {
|
||||
SystemContext systemContext = SystemContextHolder.getContext();
|
||||
if (null != systemContext) {
|
||||
// 如果更换了其他插件,则此处需要调整
|
||||
JlHttpContext jlHttpContext = (JlHttpContext) ctx;
|
||||
HTTPServer.Request request = (HTTPServer.Request) jlHttpContext.request();
|
||||
|
||||
Date receiveTime = SystemContextHolder.getContext().getReceiveTime();
|
||||
Date now = new Date();
|
||||
long elapsedTime = now.getTime() - receiveTime.getTime();
|
||||
log.info("\n-----------------------------------------------------------------接口请求日志:\n{} url:{} 执行耗时:{}\n请求体参数:{}\n响应结果:{}\n客户端IP:{}\n",
|
||||
request.getMethod(), request.getPath(), getElapsedTimeStr(elapsedTime),
|
||||
JSONObject.toJSONString(request.getParams()),
|
||||
JSONObject.toJSONString(result),
|
||||
SystemContextHolder.getIp()
|
||||
);
|
||||
}
|
||||
SystemContextHolder.remove();
|
||||
return RouterInterceptor.super.postResult(ctx, result);
|
||||
Date now = new Date();
|
||||
long elapsedTime = now.getTime() - startTime.getTime();
|
||||
log.info("\n-----------------------------------------------------------------接口请求日志:\n{} url:{} 执行耗时:{}\n请求体参数:{}\n响应结果:{}\n客户端IP:{}\n",
|
||||
ctx.method(), ctx.path(), getElapsedTimeStr(elapsedTime),
|
||||
JSONObject.toJSONString(ctx.paramMap()),
|
||||
JSONObject.toJSONString(JSONObject.toJSONString(ctx.result)),
|
||||
ctx.realIp()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,8 +25,6 @@ neutrino:
|
||||
driver-class: org.sqlite.JDBC
|
||||
username:
|
||||
password:
|
||||
job:
|
||||
enable: true
|
||||
|
||||
#添加MIME印射(如果有需要?)
|
||||
#是否启用静态文件服务。(可不配,默认为启用)
|
||||
|
||||
Reference in New Issue
Block a user