提交 5a367a6c 编写于 作者: yubinCloud's avatar yubinCloud

10-7 增加日志流水号,方便运维管理

上级 19a766ab
...@@ -3,6 +3,7 @@ package io.github.yubincloud.fairywiki.aspect; ...@@ -3,6 +3,7 @@ package io.github.yubincloud.fairywiki.aspect;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.support.spring.PropertyPreFilters; import com.alibaba.fastjson.support.spring.PropertyPreFilters;
import io.github.yubincloud.fairywiki.utils.RequestContext; import io.github.yubincloud.fairywiki.utils.RequestContext;
import io.github.yubincloud.fairywiki.utils.SnowFlake;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature; import org.aspectj.lang.Signature;
...@@ -12,11 +13,13 @@ import org.aspectj.lang.annotation.Before; ...@@ -12,11 +13,13 @@ import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -27,6 +30,9 @@ public class LogAspect { ...@@ -27,6 +30,9 @@ public class LogAspect {
private final static Logger LOG = LoggerFactory.getLogger(LogAspect.class); private final static Logger LOG = LoggerFactory.getLogger(LogAspect.class);
@Resource
private SnowFlake snowFlake;
/** 定义一个切点 */ /** 定义一个切点 */
@Pointcut("execution(public * io.github.yubincloud.fairywiki.controller..*Controller.*(..))") @Pointcut("execution(public * io.github.yubincloud.fairywiki.controller..*Controller.*(..))")
public void controllerPointcut() {} public void controllerPointcut() {}
...@@ -35,6 +41,9 @@ public class LogAspect { ...@@ -35,6 +41,9 @@ public class LogAspect {
@Before("controllerPointcut()") @Before("controllerPointcut()")
public void doBefore(JoinPoint joinPoint) { public void doBefore(JoinPoint joinPoint) {
// 增加日志流水号
MDC.put("LOG_ID", String.valueOf(snowFlake.nextId()));
// 开始打印请求日志 // 开始打印请求日志
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest(); HttpServletRequest request = attributes.getRequest();
......
package io.github.yubincloud.fairywiki.job; package io.github.yubincloud.fairywiki.job;
import io.github.yubincloud.fairywiki.service.DocService; import io.github.yubincloud.fairywiki.service.DocService;
import io.github.yubincloud.fairywiki.utils.SnowFlake;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -16,11 +18,16 @@ public class DocJob { ...@@ -16,11 +18,16 @@ public class DocJob {
@Resource @Resource
private DocService docService; private DocService docService;
@Resource
private SnowFlake snowFlake;
/** /**
* 每30秒更新电子书信息 * 每30秒更新电子书信息
*/ */
@Scheduled(cron = "5/30 * * * * ?") @Scheduled(cron = "5/30 * * * * ?")
public void cron() { public void cron() {
// 增加日志流水号
MDC.put("LOG_ID", String.valueOf(snowFlake.nextId()));
LOG.info("更新电子书下的文档数据开始"); LOG.info("更新电子书下的文档数据开始");
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
docService.updateEbookFooter(); docService.updateEbookFooter();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册