Commit 31866671 authored by jiaorz's avatar jiaorz

网关日志限制修改

parent aa0b9aba
......@@ -54,7 +54,7 @@ import java.util.stream.Stream;
*/
@Configuration
@Slf4j
public class AccessGatewayFilter implements GlobalFilter{
public class AccessGatewayFilter implements GlobalFilter {
@Autowired
@Lazy
private IUserService userService;
......@@ -257,7 +257,7 @@ public class AccessGatewayFilter implements GlobalFilter{
private boolean isStartWith(String requestUri) {
boolean flag = false;
for (String s : GATE_WAY_UNAUTH.split(",")) {
if(requestUri.contains(s)) {
if (requestUri.contains(s)) {
return true;
}
}
......@@ -286,7 +286,7 @@ public class AccessGatewayFilter implements GlobalFilter{
ServerRequest serverRequest = new DefaultServerRequest(exchange);
// 如果是json格式,将body内容转化为object or map 都可
if (MediaType.APPLICATION_JSON.isCompatibleWith(mediaType)){
if (MediaType.APPLICATION_JSON.isCompatibleWith(mediaType)) {
Mono<Object> modifiedBody = serverRequest.bodyToMono(Object.class)
.flatMap(body -> {
recordLog(exchange.getRequest(), body);
......@@ -295,7 +295,7 @@ public class AccessGatewayFilter implements GlobalFilter{
}
// 如果是表单请求
else if(MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(mediaType)){
else if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(mediaType)) {
Mono<String> modifiedBody = serverRequest.bodyToMono(String.class)
// .log("modify_request_mono", Level.INFO)
.flatMap(body -> {
......@@ -310,13 +310,15 @@ public class AccessGatewayFilter implements GlobalFilter{
// 无法兼容的请求,则不读取body,像Get请求这种
recordLog(exchange.getRequest(), "");
}
private void recordLog(ServerHttpRequest request, Object body) {
// 记录要访问的url
if (!getNotLogUri().contains(request.getURI().getRawPath())) {
StringBuilder builder = new StringBuilder();
log.info("=================请求uri:" + request.getURI().getRawPath());
// 记录访问的方法
HttpMethod method = request.getMethod();
if (null != method){
if (null != method) {
log.info("=================请求方法:" + method.name());
}
// 记录头部信息
......@@ -334,12 +336,17 @@ public class AccessGatewayFilter implements GlobalFilter{
for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) {
builder.append(entry.getKey()).append("=").append(StringUtils.join(entry.getValue(), ",")).append(",");
}
}
else {
} else {
// 从body中读取参数
builder.append(body);
}
log.info("=================请求参数:" + builder.toString());
}
}
@Value("${logback.ignore-log-path}")
String[] path;
public List<String> getNotLogUri() {
return Arrays.asList(path);
}
}
......@@ -22,7 +22,7 @@
<filter class="com.github.wxiaoqi.security.common.filter.DenyFilter"></filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_HOME}/sys.%d{yyyy-MM-dd}.log</FileNamePattern><!--日志文件输出的文件名 -->
<MaxHistory>30</MaxHistory><!--日志文件保留天数 -->
<MaxHistory>15</MaxHistory><!--日志文件保留天数 -->
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern><!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
......@@ -33,7 +33,7 @@
<filter class="com.github.wxiaoqi.security.common.filter.AcceptFilter"></filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_HOME}/log.%d{yyyy-MM-dd}.log</FileNamePattern><!--日志文件输出的文件名 -->
<MaxHistory>30</MaxHistory><!--日志文件保留天数 -->
<MaxHistory>15</MaxHistory><!--日志文件保留天数 -->
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern><!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment