mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
refactor sentinel log
This commit is contained in:
parent
eeedf90d86
commit
9168e60da4
@ -53,7 +53,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
public abstract class SentinelConverter<T extends AbstractRule>
|
||||
implements Converter<String, List<AbstractRule>> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SentinelConverter.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(SentinelConverter.class);
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@ -68,7 +68,7 @@ public abstract class SentinelConverter<T extends AbstractRule>
|
||||
public List<AbstractRule> convert(String source) {
|
||||
List<AbstractRule> ruleList = new ArrayList<>();
|
||||
if (StringUtils.isEmpty(source)) {
|
||||
logger.warn("converter can not convert rules because source is empty");
|
||||
log.warn("converter can not convert rules because source is empty");
|
||||
return ruleList;
|
||||
}
|
||||
try {
|
||||
|
@ -42,7 +42,7 @@ import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
|
||||
@EnableConfigurationProperties(SentinelProperties.class)
|
||||
public class SentinelWebAutoConfiguration {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(SentinelWebAutoConfiguration.class);
|
||||
|
||||
@Autowired
|
||||
@ -65,7 +65,7 @@ public class SentinelWebAutoConfiguration {
|
||||
Filter filter = new CommonFilter();
|
||||
registration.setFilter(filter);
|
||||
registration.setOrder(filterConfig.getOrder());
|
||||
logger.info("[Sentinel Starter] register Sentinel with urlPatterns: {}.",
|
||||
log.info("[Sentinel Starter] register Sentinel with urlPatterns: {}.",
|
||||
filterConfig.getUrlPatterns());
|
||||
return registration;
|
||||
|
||||
|
@ -53,7 +53,7 @@ import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
*/
|
||||
public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProcessor {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(SentinelBeanPostProcessor.class);
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
@ -100,14 +100,14 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
||||
return;
|
||||
}
|
||||
if (blockClass != void.class && StringUtils.isEmpty(blockMethod)) {
|
||||
logger.error(
|
||||
log.error(
|
||||
"{} class attribute exists but {} method attribute is not exists in bean[{}]",
|
||||
type, type, beanName);
|
||||
throw new IllegalArgumentException(type + " class attribute exists but "
|
||||
+ type + " method attribute is not exists in bean[" + beanName + "]");
|
||||
}
|
||||
else if (blockClass == void.class && !StringUtils.isEmpty(blockMethod)) {
|
||||
logger.error(
|
||||
log.error(
|
||||
"{} method attribute exists but {} class attribute is not exists in bean[{}]",
|
||||
type, type, beanName);
|
||||
throw new IllegalArgumentException(type + " method attribute exists but "
|
||||
@ -123,7 +123,7 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
||||
String argsStr = Arrays.toString(argList.toArray());
|
||||
Method foundMethod = ClassUtils.getStaticMethod(blockClass, blockMethod, args);
|
||||
if (foundMethod == null) {
|
||||
logger.error(
|
||||
log.error(
|
||||
"{} static method can not be found in bean[{}]. The right method signature is {}#{}{}, please check your class name, method name and arguments",
|
||||
type, beanName, blockClass.getName(), blockMethod, argsStr);
|
||||
throw new IllegalArgumentException(type
|
||||
@ -134,7 +134,7 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
||||
}
|
||||
|
||||
if (!ClientHttpResponse.class.isAssignableFrom(foundMethod.getReturnType())) {
|
||||
logger.error(
|
||||
log.error(
|
||||
"{} method return value in bean[{}] is not ClientHttpResponse: {}#{}{}",
|
||||
type, beanName, blockClass.getName(), blockMethod, argsStr);
|
||||
throw new IllegalArgumentException(type + " method return value in bean["
|
||||
|
@ -52,7 +52,7 @@ import com.alibaba.csp.sentinel.slots.block.AbstractRule;
|
||||
*/
|
||||
public class SentinelDataSourceHandler implements SmartInitializingSingleton {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(SentinelDataSourceHandler.class);
|
||||
|
||||
private List<String> dataTypeList = Arrays.asList("json", "xml");
|
||||
@ -78,7 +78,7 @@ public class SentinelDataSourceHandler implements SmartInitializingSingleton {
|
||||
try {
|
||||
List<String> validFields = dataSourceProperties.getValidField();
|
||||
if (validFields.size() != 1) {
|
||||
logger.error("[Sentinel Starter] DataSource " + dataSourceName
|
||||
log.error("[Sentinel Starter] DataSource " + dataSourceName
|
||||
+ " multi datasource active and won't loaded: "
|
||||
+ dataSourceProperties.getValidField());
|
||||
return;
|
||||
@ -90,7 +90,7 @@ public class SentinelDataSourceHandler implements SmartInitializingSingleton {
|
||||
+ validFields.get(0) + "-datasource");
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("[Sentinel Starter] DataSource " + dataSourceName
|
||||
log.error("[Sentinel Starter] DataSource " + dataSourceName
|
||||
+ " build error: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
@ -109,8 +109,8 @@ public class SentinelDataSourceHandler implements SmartInitializingSingleton {
|
||||
}
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
logger.error("[Sentinel Starter] DataSource " + dataSourceName
|
||||
+ " field: " + field.getName() + " invoke error");
|
||||
log.error("[Sentinel Starter] DataSource " + dataSourceName + " field: "
|
||||
+ field.getName() + " invoke error");
|
||||
throw new RuntimeException("[Sentinel Starter] DataSource "
|
||||
+ dataSourceName + " field: " + field.getName() + " invoke error",
|
||||
e);
|
||||
@ -157,7 +157,7 @@ public class SentinelDataSourceHandler implements SmartInitializingSingleton {
|
||||
builder.addPropertyReference("converter", customConvertBeanName);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
logger.error("[Sentinel Starter] DataSource " + dataSourceName
|
||||
log.error("[Sentinel Starter] DataSource " + dataSourceName
|
||||
+ " handle "
|
||||
+ dataSourceProperties.getClass().getSimpleName()
|
||||
+ " error, class name: "
|
||||
@ -217,14 +217,14 @@ public class SentinelDataSourceHandler implements SmartInitializingSingleton {
|
||||
ruleConfig = dataSource.loadConfig();
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("[Sentinel Starter] DataSource " + dataSourceName
|
||||
log.error("[Sentinel Starter] DataSource " + dataSourceName
|
||||
+ " loadConfig error: " + e.getMessage(), e);
|
||||
return;
|
||||
}
|
||||
if (ruleConfig instanceof List) {
|
||||
List convertedRuleList = (List) ruleConfig;
|
||||
if (CollectionUtils.isEmpty(convertedRuleList)) {
|
||||
logger.warn("[Sentinel Starter] DataSource {} rule list is empty.",
|
||||
log.warn("[Sentinel Starter] DataSource {} rule list is empty.",
|
||||
dataSourceName);
|
||||
return;
|
||||
}
|
||||
@ -235,23 +235,23 @@ public class SentinelDataSourceHandler implements SmartInitializingSingleton {
|
||||
}
|
||||
}
|
||||
if (matchCount == 0) {
|
||||
logger.error("[Sentinel Starter] DataSource {} none rules are {} type.",
|
||||
log.error("[Sentinel Starter] DataSource {} none rules are {} type.",
|
||||
dataSourceName, ruleClass.getSimpleName());
|
||||
throw new IllegalArgumentException("[Sentinel Starter] DataSource "
|
||||
+ dataSourceName + " none rules are " + ruleClass.getSimpleName()
|
||||
+ " type.");
|
||||
}
|
||||
else if (matchCount != convertedRuleList.size()) {
|
||||
logger.warn("[Sentinel Starter] DataSource {} all rules are not {} type.",
|
||||
log.warn("[Sentinel Starter] DataSource {} all rules are not {} type.",
|
||||
dataSourceName, ruleClass.getSimpleName());
|
||||
}
|
||||
else {
|
||||
logger.info("[Sentinel Starter] DataSource {} load {} {}", dataSourceName,
|
||||
log.info("[Sentinel Starter] DataSource {} load {} {}", dataSourceName,
|
||||
convertedRuleList.size(), ruleClass.getSimpleName());
|
||||
}
|
||||
}
|
||||
else {
|
||||
logger.error("[Sentinel Starter] DataSource " + dataSourceName
|
||||
log.error("[Sentinel Starter] DataSource " + dataSourceName
|
||||
+ " rule class is not List<" + ruleClass.getSimpleName()
|
||||
+ ">. Class: " + ruleConfig.getClass());
|
||||
throw new IllegalArgumentException("[Sentinel Starter] DataSource "
|
||||
|
@ -21,8 +21,6 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.alibaba.sentinel.annotation.SentinelRestTemplate;
|
||||
import org.springframework.cloud.alibaba.sentinel.rest.SentinelClientHttpResponse;
|
||||
import org.springframework.http.HttpRequest;
|
||||
@ -44,9 +42,6 @@ import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
|
||||
*/
|
||||
public class SentinelProtectInterceptor implements ClientHttpRequestInterceptor {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(SentinelProtectInterceptor.class);
|
||||
|
||||
private final SentinelRestTemplate sentinelRestTemplate;
|
||||
|
||||
public SentinelProtectInterceptor(SentinelRestTemplate sentinelRestTemplate) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user