parent
43606e3617
commit
a137fba38c
@ -0,0 +1,23 @@
|
||||
package com.xjs.business.log;
|
||||
|
||||
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xjs.business.log.domain.ApiLog;
|
||||
import com.xjs.business.log.factory.RemoteLogFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* rpc远程调用日志服务接口
|
||||
* @author xiejs
|
||||
* @since 2022-01-13
|
||||
*/
|
||||
@FeignClient(contextId = "remoteLogFeign",
|
||||
value = ServiceNameConstants.BUSINESS_LOG_SERVICE,
|
||||
fallbackFactory = RemoteLogFactory.class)
|
||||
public interface RemoteLogFeign {
|
||||
|
||||
@PostMapping("/apilog/forPRC")
|
||||
R<Object> saveApiLog(@RequestBody ApiLog apiLog);
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package com.xjs.business.log.domain;
|
||||
|
||||
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
public class ApiLog implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 接口名称
|
||||
*/
|
||||
private String apiName;
|
||||
|
||||
/**
|
||||
* 请求API的url
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 请求API的方法
|
||||
*/
|
||||
private String method;
|
||||
|
||||
/**
|
||||
* 请求request
|
||||
*/
|
||||
private String request;
|
||||
|
||||
/**
|
||||
* 响应体
|
||||
*/
|
||||
private String response;
|
||||
|
||||
/**
|
||||
* 是否请求成功
|
||||
*/
|
||||
private Integer isSuccess;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getApiName() {
|
||||
return apiName;
|
||||
}
|
||||
|
||||
public void setApiName(String apiName) {
|
||||
this.apiName = apiName;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
public void setRequest(String request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public String getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
public void setResponse(String response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public Integer getIsSuccess() {
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
public void setIsSuccess(Integer isSuccess) {
|
||||
this.isSuccess = isSuccess;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.xjs.business.log.factory;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xjs.business.api.factory.RemoteTranDictFactory;
|
||||
import com.xjs.business.log.RemoteLogFeign;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 日志远程调用rpc服务降级处理
|
||||
* @author xiejs
|
||||
* @since 2022-01-13
|
||||
*/
|
||||
@Component
|
||||
public class RemoteLogFactory implements FallbackFactory<RemoteLogFeign> {
|
||||
private static final Logger log = LoggerFactory.getLogger(RemoteLogFactory.class);
|
||||
|
||||
@Override
|
||||
public RemoteLogFeign create(Throwable cause) {
|
||||
log.error("日志模块服务添加调用失败:{}", cause.getMessage());
|
||||
return apiLog -> R.fail("日志模块服务添加调用失败" + cause.getMessage());
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.xjs.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 服务之间的调用注解
|
||||
* @author xiejs
|
||||
* @since 2022-01-13
|
||||
*/
|
||||
@Target({ ElementType.PARAMETER, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface RpcLog {
|
||||
/**
|
||||
* 请求服务方法
|
||||
* @return String
|
||||
*/
|
||||
String method() default "";
|
||||
|
||||
/**
|
||||
* 请求服务名称
|
||||
* @return String
|
||||
*/
|
||||
String serviceName() default "";
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>xjs-business</artifactId>
|
||||
<groupId>com.xjs</groupId>
|
||||
<version>3.3.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<name>业务模块-日志模块</name>
|
||||
|
||||
<artifactId>xjs-business-log</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.xjs</groupId>
|
||||
<artifactId>xjs-business-common</artifactId>
|
||||
<version>3.3.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,22 @@
|
||||
package com.xjs;
|
||||
|
||||
import com.ruoyi.common.security.annotation.EnableCustomConfig;
|
||||
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
|
||||
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* 日志服务启动器
|
||||
* @author xiejs
|
||||
* 2021-12-31
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableRyFeignClients
|
||||
public class XjsLogApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(XjsLogApp.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
Spring Boot Version: ${spring-boot.version}
|
||||
Spring Application Name: ${spring.application.name}
|
||||
____ ___ ____. _________ _____.___._____.___.________ _________
|
||||
\ \/ / | |/ _____/ \__ | |\__ | |\______ \ / _____/
|
||||
\ / | |\_____ \ ______ / | | / | | | | \ \_____ \
|
||||
/ \/\__| |/ \ /_____/ \____ | \____ | | ` \/ \
|
||||
/___/\ \________/_______ / / ______| / ______|/_______ /_______ /
|
||||
\_/ \/ \/ \/ \/ \/
|
@ -0,0 +1,29 @@
|
||||
# Tomcat
|
||||
server:
|
||||
port: 9904
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: xjs-log
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 127.0.0.1:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 127.0.0.1:8848
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
#配置组
|
||||
group: xjs
|
||||
#命名空间
|
||||
namespace: xjs-666
|
@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/xjs-log"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.xjs" level="info" />
|
||||
<!--打印feign DEBUG日志-->
|
||||
<logger name="com.xjs.common.client" level="debug"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn" />
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info" />
|
||||
<appender-ref ref="file_error" />
|
||||
</root>
|
||||
</configuration>
|
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
|
||||
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
|
||||
-->
|
||||
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
|
||||
|
||||
<id>xjs-business-log</id>
|
||||
|
||||
<classpath>
|
||||
<dir name="D:/Dev/IdeaPerject/GitHub/RuoYi-Cloud/xjs-business/xjs-business-log/target/classes">
|
||||
</dir>
|
||||
</classpath>
|
||||
|
||||
</application>
|
Loading…
Reference in new issue