From 226151bee3b84d051a55d6e2834cf43200d45501 Mon Sep 17 00:00:00 2001 From: smallchill Date: Fri, 28 Dec 2018 15:17:35 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/boot/logger/RequestLogAspect.java | 6 ++-- .../config/BladeLogToolAutoConfiguration.java | 6 ++-- ...{BladeLogEvent.java => UsualLogEvent.java} | 4 +-- ...LogListener.java => UsualLogListener.java} | 32 +++++++++---------- .../core/log/feign/ILogClient.java | 6 ++-- .../model/{LogBlade.java => LogUsual.java} | 4 +-- .../core/log/publisher/BladeLogPublisher.java | 16 +++++----- .../org/springblade/core/secure/AuthInfo.java | 2 ++ .../core/secure/utils/SecureUtil.java | 2 +- 9 files changed, 39 insertions(+), 39 deletions(-) rename blade-core-log/src/main/java/org/springblade/core/log/event/{BladeLogEvent.java => UsualLogEvent.java} (88%) rename blade-core-log/src/main/java/org/springblade/core/log/event/{BladeLogListener.java => UsualLogListener.java} (69%) rename blade-core-log/src/main/java/org/springblade/core/log/model/{LogBlade.java => LogUsual.java} (96%) diff --git a/blade-core-boot/src/main/java/org/springblade/core/boot/logger/RequestLogAspect.java b/blade-core-boot/src/main/java/org/springblade/core/boot/logger/RequestLogAspect.java index 15c213d..8d5614c 100644 --- a/blade-core-boot/src/main/java/org/springblade/core/boot/logger/RequestLogAspect.java +++ b/blade-core-boot/src/main/java/org/springblade/core/boot/logger/RequestLogAspect.java @@ -54,12 +54,9 @@ public class RequestLogAspect { MethodSignature ms = (MethodSignature) point.getSignature(); Method method = ms.getMethod(); Object[] args = point.getArgs(); - // 请求参数处理 final Map paraMap = new HashMap<>(16); for (int i = 0; i < args.length; i++) { - // 读取方法参数 MethodParameter methodParam = ClassUtil.getMethodParameter(method, i); - // PathVariable 参数跳过 PathVariable pathVariable = methodParam.getParameterAnnotation(PathVariable.class); if (pathVariable != null) { continue; @@ -70,7 +67,6 @@ public class RequestLogAspect { if (requestBody != null && object != null) { paraMap.putAll(BeanUtil.toMap(object)); } else { - // 参数名 RequestParam requestParam = methodParam.getParameterAnnotation(RequestParam.class); String paraName; if (requestParam != null && StringUtil.isNotBlank(requestParam.value())) { @@ -106,6 +102,7 @@ public class RequestLogAspect { }); needRemoveKeys.forEach(paraMap::remove); // 打印请求 + log.info("================ Request Start ================"); if (paraMap.isEmpty()) { log.info("===> {}: {}", requestMethod, requestURI); } else { @@ -127,6 +124,7 @@ public class RequestLogAspect { } finally { long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs); log.info("<=== {}: {} ({} ms)", request.getMethod(), requestURI, tookMs); + log.info("================ Request End ================"); } } diff --git a/blade-core-log/src/main/java/org/springblade/core/log/config/BladeLogToolAutoConfiguration.java b/blade-core-log/src/main/java/org/springblade/core/log/config/BladeLogToolAutoConfiguration.java index 07ddbe6..2ec0069 100644 --- a/blade-core-log/src/main/java/org/springblade/core/log/config/BladeLogToolAutoConfiguration.java +++ b/blade-core-log/src/main/java/org/springblade/core/log/config/BladeLogToolAutoConfiguration.java @@ -19,7 +19,7 @@ package org.springblade.core.log.config; import lombok.AllArgsConstructor; import org.springblade.core.log.aspect.ApiLogAspect; import org.springblade.core.log.event.ApiLogListener; -import org.springblade.core.log.event.BladeLogListener; +import org.springblade.core.log.event.UsualLogListener; import org.springblade.core.log.event.ErrorLogListener; import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.launch.props.BladeProperties; @@ -64,8 +64,8 @@ public class BladeLogToolAutoConfiguration { } @Bean - public BladeLogListener bladeEventListener() { - return new BladeLogListener(logService, serverInfo, bladeProperties); + public UsualLogListener bladeEventListener() { + return new UsualLogListener(logService, serverInfo, bladeProperties); } } diff --git a/blade-core-log/src/main/java/org/springblade/core/log/event/BladeLogEvent.java b/blade-core-log/src/main/java/org/springblade/core/log/event/UsualLogEvent.java similarity index 88% rename from blade-core-log/src/main/java/org/springblade/core/log/event/BladeLogEvent.java rename to blade-core-log/src/main/java/org/springblade/core/log/event/UsualLogEvent.java index 48d5e6f..5d3a1de 100644 --- a/blade-core-log/src/main/java/org/springblade/core/log/event/BladeLogEvent.java +++ b/blade-core-log/src/main/java/org/springblade/core/log/event/UsualLogEvent.java @@ -25,9 +25,9 @@ import java.util.Map; * * @author smallchill */ -public class BladeLogEvent extends ApplicationEvent { +public class UsualLogEvent extends ApplicationEvent { - public BladeLogEvent(Map source) { + public UsualLogEvent(Map source) { super(source); } diff --git a/blade-core-log/src/main/java/org/springblade/core/log/event/BladeLogListener.java b/blade-core-log/src/main/java/org/springblade/core/log/event/UsualLogListener.java similarity index 69% rename from blade-core-log/src/main/java/org/springblade/core/log/event/BladeLogListener.java rename to blade-core-log/src/main/java/org/springblade/core/log/event/UsualLogListener.java index c0e7532..520cf43 100644 --- a/blade-core-log/src/main/java/org/springblade/core/log/event/BladeLogListener.java +++ b/blade-core-log/src/main/java/org/springblade/core/log/event/UsualLogListener.java @@ -22,7 +22,7 @@ import org.springblade.core.launch.props.BladeProperties; import org.springblade.core.launch.server.ServerInfo; import org.springblade.core.log.constant.EventConstant; import org.springblade.core.log.feign.ILogClient; -import org.springblade.core.log.model.LogBlade; +import org.springblade.core.log.model.LogUsual; import org.springblade.core.secure.utils.SecureUtil; import org.springblade.core.tool.utils.UrlUtil; import org.springblade.core.tool.utils.WebUtil; @@ -43,7 +43,7 @@ import java.util.Map; @Slf4j @Component @AllArgsConstructor -public class BladeLogListener { +public class UsualLogListener { private final ILogClient logService; private final ServerInfo serverInfo; @@ -51,22 +51,22 @@ public class BladeLogListener { @Async @Order - @EventListener(BladeLogEvent.class) - public void saveBladeLog(BladeLogEvent event) { + @EventListener(UsualLogEvent.class) + public void saveUsualLog(UsualLogEvent event) { Map source = (Map) event.getSource(); - LogBlade logBlade = (LogBlade) source.get(EventConstant.EVENT_LOG); + LogUsual logUsual = (LogUsual) source.get(EventConstant.EVENT_LOG); HttpServletRequest request = (HttpServletRequest) source.get(EventConstant.EVENT_REQUEST); - logBlade.setRequestUri(UrlUtil.getPath(request.getRequestURI())); - logBlade.setUserAgent(request.getHeader(WebUtil.USER_AGENT_HEADER)); - logBlade.setMethod(request.getMethod()); - logBlade.setParams(WebUtil.getRequestParamString(request)); - logBlade.setServerHost(serverInfo.getHostName()); - logBlade.setServiceId(bladeProperties.getName()); - logBlade.setEnv(bladeProperties.getEnv()); - logBlade.setServerIp(serverInfo.getIPWithPort()); - logBlade.setCreateBy(SecureUtil.getUserAccount(request)); - logBlade.setCreateTime(LocalDateTime.now()); - logService.saveBladeLog(logBlade); + logUsual.setRequestUri(UrlUtil.getPath(request.getRequestURI())); + logUsual.setUserAgent(request.getHeader(WebUtil.USER_AGENT_HEADER)); + logUsual.setMethod(request.getMethod()); + logUsual.setParams(WebUtil.getRequestParamString(request)); + logUsual.setServerHost(serverInfo.getHostName()); + logUsual.setServiceId(bladeProperties.getName()); + logUsual.setEnv(bladeProperties.getEnv()); + logUsual.setServerIp(serverInfo.getIPWithPort()); + logUsual.setCreateBy(SecureUtil.getUserAccount(request)); + logUsual.setCreateTime(LocalDateTime.now()); + logService.saveUsualLog(logUsual); } } diff --git a/blade-core-log/src/main/java/org/springblade/core/log/feign/ILogClient.java b/blade-core-log/src/main/java/org/springblade/core/log/feign/ILogClient.java index 276641c..9f4a627 100644 --- a/blade-core-log/src/main/java/org/springblade/core/log/feign/ILogClient.java +++ b/blade-core-log/src/main/java/org/springblade/core/log/feign/ILogClient.java @@ -17,7 +17,7 @@ package org.springblade.core.log.feign; import org.springblade.core.launch.constant.AppConstant; import org.springblade.core.log.model.LogApi; -import org.springblade.core.log.model.LogBlade; +import org.springblade.core.log.model.LogUsual; import org.springblade.core.log.model.LogError; import org.springblade.core.tool.api.R; import org.springframework.cloud.openfeign.FeignClient; @@ -42,8 +42,8 @@ public interface ILogClient { * @param log * @return */ - @PostMapping(API_PREFIX + "/saveBladeLog") - R saveBladeLog(@RequestBody LogBlade log); + @PostMapping(API_PREFIX + "/saveUsualLog") + R saveUsualLog(@RequestBody LogUsual log); /** * 保存操作日志 diff --git a/blade-core-log/src/main/java/org/springblade/core/log/model/LogBlade.java b/blade-core-log/src/main/java/org/springblade/core/log/model/LogUsual.java similarity index 96% rename from blade-core-log/src/main/java/org/springblade/core/log/model/LogBlade.java rename to blade-core-log/src/main/java/org/springblade/core/log/model/LogUsual.java index c489eff..416a718 100644 --- a/blade-core-log/src/main/java/org/springblade/core/log/model/LogBlade.java +++ b/blade-core-log/src/main/java/org/springblade/core/log/model/LogUsual.java @@ -34,8 +34,8 @@ import java.time.LocalDateTime; * @since 2018-10-12 */ @Data -@TableName("blade_log") -public class LogBlade implements Serializable { +@TableName("blade_log_usual") +public class LogUsual implements Serializable { private static final long serialVersionUID = 1L; diff --git a/blade-core-log/src/main/java/org/springblade/core/log/publisher/BladeLogPublisher.java b/blade-core-log/src/main/java/org/springblade/core/log/publisher/BladeLogPublisher.java index 9990019..1bbcc6c 100644 --- a/blade-core-log/src/main/java/org/springblade/core/log/publisher/BladeLogPublisher.java +++ b/blade-core-log/src/main/java/org/springblade/core/log/publisher/BladeLogPublisher.java @@ -17,10 +17,10 @@ package org.springblade.core.log.publisher; import org.springblade.core.log.constant.EventConstant; -import org.springblade.core.log.event.BladeLogEvent; +import org.springblade.core.log.event.UsualLogEvent; import org.springblade.core.tool.utils.SpringUtil; import org.springblade.core.tool.utils.WebUtil; -import org.springblade.core.log.model.LogBlade; +import org.springblade.core.log.model.LogUsual; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; @@ -35,14 +35,14 @@ public class BladeLogPublisher { public static void publishEvent(String level, String id, String data) { HttpServletRequest request = WebUtil.getRequest(); - LogBlade logBlade = new LogBlade(); - logBlade.setLogLevel(level); - logBlade.setLogId(id); - logBlade.setLogData(data); + LogUsual logUsual = new LogUsual(); + logUsual.setLogLevel(level); + logUsual.setLogId(id); + logUsual.setLogData(data); Map event = new HashMap<>(16); - event.put(EventConstant.EVENT_LOG, logBlade); + event.put(EventConstant.EVENT_LOG, logUsual); event.put(EventConstant.EVENT_REQUEST, request); - SpringUtil.publishEvent(new BladeLogEvent(event)); + SpringUtil.publishEvent(new UsualLogEvent(event)); } } diff --git a/blade-core-secure/src/main/java/org/springblade/core/secure/AuthInfo.java b/blade-core-secure/src/main/java/org/springblade/core/secure/AuthInfo.java index 69d7a51..1504a7e 100644 --- a/blade-core-secure/src/main/java/org/springblade/core/secure/AuthInfo.java +++ b/blade-core-secure/src/main/java/org/springblade/core/secure/AuthInfo.java @@ -31,6 +31,8 @@ public class AuthInfo { private String accessToken; @ApiModelProperty(value = "令牌类型") private String tokenType; + @ApiModelProperty(value = "头像") + private String avatar = "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png"; @ApiModelProperty(value = "角色名") private String authority; @ApiModelProperty(value = "用户名") diff --git a/blade-core-secure/src/main/java/org/springblade/core/secure/utils/SecureUtil.java b/blade-core-secure/src/main/java/org/springblade/core/secure/utils/SecureUtil.java index 66e22f3..17b143e 100644 --- a/blade-core-secure/src/main/java/org/springblade/core/secure/utils/SecureUtil.java +++ b/blade-core-secure/src/main/java/org/springblade/core/secure/utils/SecureUtil.java @@ -50,7 +50,7 @@ public class SecureUtil { public final static Integer AUTH_LENGTH = 7; private static String BASE64_SECURITY = DatatypeConverter.printBase64Binary("SpringBlade".getBytes()); - /**6 + /** * 获取用户信息 * * @return