From cee2a5560583e9b512ded91ccfc788259089dec8 Mon Sep 17 00:00:00 2001 From: LuoYe Date: Thu, 16 Sep 2021 09:14:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=BF=AE=E6=94=B9=E4=B8=BAlo?= =?UTF-8?q?g4j2=EF=BC=8C=E5=A2=9E=E5=8A=A0=E8=B7=9F=E8=B8=AAid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 19 ++++++++--- src/main/java/io/qyi/e5/advice/LogAop.java | 34 +++++++++++++++++++ .../outlook/controller/OutlookController.java | 4 +++ .../service/impl/OutlookServiceImpl.java | 3 ++ .../controller/OutlookLogController.java | 13 +++---- src/main/resources/application.properties | 2 +- src/main/resources/log4j2.xml | 2 +- 7 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 src/main/java/io/qyi/e5/advice/LogAop.java diff --git a/pom.xml b/pom.xml index 6c50320..bc10409 100644 --- a/pom.xml +++ b/pom.xml @@ -20,21 +20,23 @@ - org.springframework.boot spring-boot-starter-logging - --> + org.springframework.boot spring-boot-starter-web + org.springframework.boot spring-boot-starter-test @@ -48,10 +50,10 @@ - + @@ -73,8 +75,10 @@ org.projectlombok lombok - true + 1.18.20 + provided + commons-lang @@ -183,6 +187,11 @@ 3.1.0 + + org.springframework.boot + spring-boot-starter-aop + + diff --git a/src/main/java/io/qyi/e5/advice/LogAop.java b/src/main/java/io/qyi/e5/advice/LogAop.java new file mode 100644 index 0000000..c6a922e --- /dev/null +++ b/src/main/java/io/qyi/e5/advice/LogAop.java @@ -0,0 +1,34 @@ +package io.qyi.e5.advice; + +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.After; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; +import org.slf4j.MDC; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Aspect +@Component +public class LogAop { + private static String MDC_KEY_USER_NAME = "userName"; + private static String MDC_KEY_REQ_ID = "reqId"; + + @Pointcut("@annotation(org.springframework.web.bind.annotation.GetMapping)") + public void logAdvicePointcut(){ + + } + + @Before("logAdvicePointcut()") + public void logAdvice(JoinPoint joinPoint){ + MDC.put(MDC_KEY_REQ_ID, UUID.randomUUID().toString()); + + } + + @After("logAdvicePointcut()") + public void afterLogAdvice(){ + MDC.remove(MDC_KEY_REQ_ID); + } +} diff --git a/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java b/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java index 1935936..6ed51fa 100644 --- a/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java +++ b/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java @@ -122,6 +122,10 @@ public class OutlookController { @GetMapping("/getOutlookList") public Result getOutlookList() { + log.info("测试MOD"); + log.debug("测试MOD"); + log.warn("测试MOD"); + log.error("测试MOD"); UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); int github_id = authentication.getGithub_id(); List outlooklist = outlookService.getOutlooklist(github_id); diff --git a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java index 909242c..86041a3 100644 --- a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java +++ b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java @@ -15,6 +15,7 @@ import io.qyi.e5.outlook.mapper.OutlookMapper; import io.qyi.e5.outlook.service.IOutlookService; import io.qyi.e5.util.netRequest.*; import io.qyi.e5.util.redis.RedisUtil; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,6 +35,7 @@ import java.util.Map; * @author 落叶 * @since 2020-02-24 */ +@Slf4j @Service public class OutlookServiceImpl extends ServiceImpl implements IOutlookService { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -367,6 +369,7 @@ public class OutlookServiceImpl extends ServiceImpl impl */ @Override public List getOutlooklist(int github_id) { + log.info("测试MOD service"); QueryWrapper qw = new QueryWrapper().eq("github_id", github_id); List outlooks = baseMapper.selectList(qw); return outlooks; diff --git a/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java b/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java index 1f9d1c6..6d64ad5 100644 --- a/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java +++ b/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java @@ -5,22 +5,18 @@ import com.influxdb.client.InfluxDBClient; import io.qyi.e5.bean.result.Result; import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken; import io.qyi.e5.outlook.service.IOutlookService; -import io.qyi.e5.outlook_log.bena.LogVo; import io.qyi.e5.outlook_log.entity.OutlookLog; import io.qyi.e5.outlook_log.service.IOutlookLogService; import io.qyi.e5.util.ResultUtil; -import org.springframework.beans.BeanUtils; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; -import java.util.Iterator; -import java.util.LinkedList; import java.util.List; /** @@ -31,7 +27,8 @@ import java.util.List; * @author 落叶 * @since 2020-03-03 */ -@Controller +// @Slf4j +@RestController @RequestMapping("/outlookLog") public class OutlookLogController { @@ -57,8 +54,8 @@ public class OutlookLogController { private int pageSize; @GetMapping("/findLog") - @ResponseBody public Result findLog(@RequestParam int outlookId){ + // log.info("查询"); UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); int github_id = authentication.getGithub_id(); List list = outlookLogService.findAllList(github_id, outlookId); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 257b306..e295525 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ -spring.profiles.active=dev \ No newline at end of file +spring.profiles.active=online \ No newline at end of file diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml index 5999d31..e389c4d 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -7,7 +7,7 @@ - +