mirror of
https://github.com/luoye663/e5.git
synced 2024-12-26 11:48:50 +00:00
日志修改为log4j2,增加跟踪id
This commit is contained in:
parent
c8591e0fd0
commit
cee2a55605
19
pom.xml
19
pom.xml
@ -20,21 +20,23 @@
|
||||
|
||||
<dependencies>
|
||||
<!--排除自带的logging-->
|
||||
<!--<dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<exclusions>
|
||||
<!--排除 springboot 默认的 logback 依赖 -->
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>-->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
@ -48,10 +50,10 @@
|
||||
</dependency>
|
||||
|
||||
<!-- 引入log4j2依赖 -->
|
||||
<!--<dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||
</dependency>-->
|
||||
</dependency>
|
||||
|
||||
<!--权限管理插件-->
|
||||
<dependency>
|
||||
@ -73,8 +75,10 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
<version>1.18.20</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- commons-lang -->
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
@ -183,6 +187,11 @@
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<!--webflux依赖-->
|
||||
|
34
src/main/java/io/qyi/e5/advice/LogAop.java
Normal file
34
src/main/java/io/qyi/e5/advice/LogAop.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
@ -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<Outlook> outlooklist = outlookService.getOutlooklist(github_id);
|
||||
|
@ -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<OutlookMapper, Outlook> implements IOutlookService {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
@ -367,6 +369,7 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
|
||||
*/
|
||||
@Override
|
||||
public List<Outlook> getOutlooklist(int github_id) {
|
||||
log.info("测试MOD service");
|
||||
QueryWrapper<Outlook> qw = new QueryWrapper<Outlook>().eq("github_id", github_id);
|
||||
List<Outlook> outlooks = baseMapper.selectList(qw);
|
||||
return outlooks;
|
||||
|
@ -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<OutlookLog> list = outlookLogService.findAllList(github_id, outlookId);
|
||||
|
@ -1 +1 @@
|
||||
spring.profiles.active=dev
|
||||
spring.profiles.active=online
|
@ -7,7 +7,7 @@
|
||||
<configuration status="INFO" monitorInterval="5">
|
||||
<Properties>
|
||||
<!-- 日志模板 -->
|
||||
<Property name="log_pattern" value="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
|
||||
<Property name="log_pattern" value="[%d{HH:mm:ss:SSS}] [%p] reqId: [%X{reqId}] - %l - %m%n"/>
|
||||
<!-- 存储日志文件路径 -->
|
||||
<Property name="file_path" value="logs/log"/>
|
||||
<!-- 日志文件的最大容量,超过该值就进行备份 -->
|
||||
|
Loading…
Reference in New Issue
Block a user