a0cfa949 by 李墨

[fix]:修复日志打印

1 parent 48cd3c63
......@@ -48,6 +48,13 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 日志组件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
......
package com.seektruth.demo.spring.boot.resilience4j;
import com.seektruth.demo.spring.boot.resilience4j.config.RegistryEventBeanConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationEvent;
......@@ -13,12 +16,13 @@ import org.springframework.context.event.ContextClosedEvent;
*/
@SpringBootApplication
public class BootStrap {
private static final Logger LOG = LoggerFactory.getLogger(BootStrap.class);
public static void main(String[] args) {
ConfigurableApplicationContext ctx = SpringApplication.run(BootStrap.class,args);
boolean running = ctx.isRunning();
if(running){
System.out.println("启动已启动");
LOG.info("启动已启动");
}
}
}
......
......@@ -7,10 +7,12 @@ import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
/**
* 操作日志切面
*/
@Component
@Aspect
public class OperateLogAspect implements Ordered {
private static final Logger LOG = LoggerFactory.getLogger(OperateLogAspect.class);
......@@ -18,7 +20,7 @@ public class OperateLogAspect implements Ordered {
/**
* 设置切入点:横切所有 controller 类的所有方法
*/
@Pointcut("execution(* com.seektruth.demo.spring.boot.resillience4j.controller.*.*(..))")
@Pointcut("execution(* com.seektruth.demo.spring.boot.resilience4j.controller.*.*(..))")
public void operateLogPointcut() {
// 该方法无方法体,主要为了让同类中其他方法使用此切入点
}
......@@ -35,8 +37,10 @@ public class OperateLogAspect implements Ordered {
Object[] args = joinPoint.getArgs();
LOG.info("========================================");
LOG.info(" 操作日志打印:调用 {} {} 方法,请求参数:{}",className,methodName,args);
Object result = joinPoint.proceed(args);
LOG.info(" 操作日志打印:{} {} 方法,返回结果:{}",result);
LOG.info("========================================");
return joinPoint.proceed(args);
return result;
}
@Override
......
package com.seektruth.demo.spring.boot.resilience4j.controller;
import com.seektruth.demo.spring.boot.resilience4j.BootStrap;
import io.github.resilience4j.bulkhead.BulkheadFullException;
import io.github.resilience4j.circuitbreaker.CallNotPermittedException;
import io.github.resilience4j.ratelimiter.RequestNotPermitted;
import io.github.resilience4j.retry.MaxRetriesExceededException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 降级方法
*/
public class BaseController {
private static final Logger LOG = LoggerFactory.getLogger(BaseController.class);
public String fallback(CallNotPermittedException ex){
LOG.info("服务已熔断。");
return "服务已熔断。";
}
public String fallback(BulkheadFullException ex){
LOG.info("服务并发限制,不允许访问。");
return "服务并发限制,不允许访问。";
}
public String fallback(RequestNotPermitted ex){
LOG.info("限速了不允许访问了。");
return "限速了不允许访问了。";
}
public String fallback(MaxRetriesExceededException ex){
LOG.info("重试过多,不允许访问。");
return "重试过多,不允许访问。";
}
public String fallback(Throwable ex){
LOG.info("服务降级了。");
return "服务降级了。";
}
}
......
......@@ -186,3 +186,7 @@ resilience4j.TimeLimiter:
instances:
timelimiterInstance:
baseConfig: base
# 日志信息
logger:
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!