springcloud_k8s_panzhihuazhihuishequ/zuul/src/main/java/com/panzhihua/zuul/filters/SercuritFilter.java
@@ -8,6 +8,8 @@ import javax.annotation.Resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.ValueOperations; import org.springframework.security.access.ConfigAttribute; @@ -38,7 +40,8 @@ private StringRedisTemplate stringRedisTemplate; @Resource private UserService userService; // 记录特定日志的声明 private final Logger newLogger = LoggerFactory.getLogger("requestLog"); /** * 获取当前url对应的角色 * @@ -53,6 +56,12 @@ List<ConfigAttribute> configAttributes = new ArrayList<>(); String requestUrl = ((FilterInvocation)o).getRequestUrl(); log.info("接口请求地址【{}】", requestUrl); try { String remoteHost = ((FilterInvocation)o).getRequest().getRemoteHost(); newLogger.info("IP:{},接口请求地址【{}】", remoteHost, requestUrl); } catch (Exception e) { log.info("zuul 访问信息解析错误:【{}】", e.getMessage()); } Boolean aBoolean = stringRedisTemplate.hasKey(SecurityConstants.ROLE_ALL); ValueOperations<String, String> valueOperations = stringRedisTemplate.opsForValue(); List<MenuVO> menuVOS = new ArrayList<>(); springcloud_k8s_panzhihuazhihuishequ/zuul/src/main/resources/logback-spring.xml
@@ -48,4 +48,31 @@ <appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> </root> <!--不同业务日志记录到不同的文件--> <appender name="requestAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>logs/request.log</File> <append>true</append> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>INFO</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${LOG_HOME}/request.%d.%i.log</fileNamePattern> <maxHistory>10</maxHistory> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>10MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <encoder> <pattern>%d{yyyy/MM/dd HH:mm:ss.SSS} %-5level [%thread] [%c{0}:%L] : %msg%n</pattern> <charset>UTF-8</charset> </encoder> </appender> <!--这是我们定义的访问日志传入的名称--> <logger name="requestLog" additivity="false" level="INFO"> <appender-ref ref="requestAppender"/> </logger> </configuration>