feat:日志切面完善

This commit is contained in:
haoxr 2021-03-03 00:14:57 +08:00
parent 2e4c81dcc6
commit 28c455715c
5 changed files with 17 additions and 15 deletions

View File

@ -2,6 +2,7 @@ package com.youlai.admin.api;
import com.youlai.admin.pojo.dto.UserDTO; import com.youlai.admin.pojo.dto.UserDTO;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;

View File

@ -1,11 +1,13 @@
package com.youlai; package com.youlai.auth;
import com.youlai.admin.api.UserFeignService;
import com.youlai.mall.ums.api.MemberFeignService;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableFeignClients @EnableFeignClients(basePackageClasses = {UserFeignService.class, MemberFeignService.class})
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
public class AuthApplication { public class AuthApplication {

View File

@ -1,11 +1,9 @@
package com.youlai.common.web.aspect; package com.youlai.common.web.aspect;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.youlai.common.web.pojo.domain.LoginLog;
import com.youlai.common.web.pojo.domain.OptLog; import com.youlai.common.web.pojo.domain.OptLog;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.logstash.logback.marker.Markers; import net.logstash.logback.marker.Markers;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature; import org.aspectj.lang.Signature;
@ -25,16 +23,16 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* @Author HXR * @author HXR
* @CreateTime 2021-03-01 16:47 * @date 2021-03-01 16:47
*/ */
@Aspect @Aspect
@Component @Component
@AllArgsConstructor @AllArgsConstructor
public class OptLogAspect { public class LogAspect {
private static final Logger LOGGER = LoggerFactory.getLogger(OptLogAspect.class); private static final Logger LOGGER = LoggerFactory.getLogger(LogAspect.class);
@Pointcut("execution(public * com.youlai..*.controller.*.*(..)) || execution(public * com.youlai.*.controller.*(..))") @Pointcut("@annotation(io.swagger.annotations.ApiOperation)")
public void Log() { public void Log() {
} }

View File

@ -1,3 +1,4 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.youlai.common.web.config.WebMvcConfig,\ com.youlai.common.web.config.WebMvcConfig,\
com.youlai.common.web.exception.GlobalExceptionHandler com.youlai.common.web.exception.GlobalExceptionHandler,\
com.youlai.common.web.aspect.LogAspect

View File

@ -63,7 +63,7 @@
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level> <level>DEBUG</level>
</filter> </filter>
<destination>${LOG_STASH_HOST}:5044</destination> <destination>${LOG_STASH_HOST}:4560</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> <encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers> <providers>
<timestamp> <timestamp>
@ -101,7 +101,7 @@
<onMatch>ACCEPT</onMatch> <onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch> <onMismatch>DENY</onMismatch>
</filter> </filter>
<destination>${LOG_STASH_HOST}:5044</destination> <destination>${LOG_STASH_HOST}:4560</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> <encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers> <providers>
<timestamp> <timestamp>
@ -134,7 +134,7 @@
<!--业务日志输出到LogStash--> <!--业务日志输出到LogStash-->
<appender name="LOG_STASH_BUSINESS" class="net.logstash.logback.appender.LogstashTcpSocketAppender"> <appender name="LOG_STASH_BUSINESS" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>${LOG_STASH_HOST}:5044</destination> <destination>${LOG_STASH_HOST}:4560</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> <encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers> <providers>
<timestamp> <timestamp>
@ -167,7 +167,7 @@
<!--接口访问记录日志输出到LogStash--> <!--接口访问记录日志输出到LogStash-->
<appender name="LOG_STASH_RECORD" class="net.logstash.logback.appender.LogstashTcpSocketAppender"> <appender name="LOG_STASH_RECORD" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>${LOG_STASH_HOST}:5044</destination> <destination>${LOG_STASH_HOST}:4560</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> <encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers> <providers>
<timestamp> <timestamp>
@ -211,7 +211,7 @@
<appender-ref ref="LOG_STASH_ERROR"/> <appender-ref ref="LOG_STASH_ERROR"/>
</root> </root>
<logger name="com.youlai.common.web.aspect.OptLogAspect" level="DEBUG"> <logger name="com.youlai.common.web.aspect.LogAspect" level="DEBUG">
<appender-ref ref="LOG_STASH_RECORD"/> <appender-ref ref="LOG_STASH_RECORD"/>
</logger> </logger>