feat: 2.6.0
1. 修复日志打印参数错误问题
This commit is contained in:
parent
1e2f4d55bb
commit
ba2bd3f6a5
@ -32,8 +32,17 @@ public class SpringContext implements ApplicationContextAware {
|
||||
public static synchronized <T> T getBean(String name) {
|
||||
try {
|
||||
return (T) CONTEXT.getBean(name);
|
||||
} catch (BeansException var2) {
|
||||
log.error(" BeanName:{} not exist,Exception => {}", name, var2.getMessage());
|
||||
} catch (BeansException | NullPointerException exception) {
|
||||
log.error(" BeanName:{} not exist,Exception => {}", name, exception.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized <T> T getBean(Class<T> requiredType) {
|
||||
try {
|
||||
return CONTEXT.getBean(requiredType);
|
||||
} catch (BeansException | NullPointerException exception) {
|
||||
log.error(" BeanName:{} not exist,Exception => {}", requiredType.getName(), exception.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -41,8 +50,8 @@ public class SpringContext implements ApplicationContextAware {
|
||||
public static synchronized <T> T getBean(String name, Class<T> requiredType) {
|
||||
try {
|
||||
return CONTEXT.getBean(name, requiredType);
|
||||
} catch (BeansException | NullPointerException var3) {
|
||||
log.error(" BeanName:{} not exist,Exception => {}", name, var3.getMessage());
|
||||
} catch (BeansException | NullPointerException exception) {
|
||||
log.error(" BeanName:{} not exist,Exception => {}", name, exception.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package com.aizuda.easy.retry.common.core.util;
|
||||
import com.aizuda.easy.retry.common.core.context.SpringContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 获取环境信息
|
||||
*
|
||||
@ -10,8 +12,6 @@ import org.springframework.core.env.Environment;
|
||||
* @date : 2021-12-01 14:27
|
||||
*/
|
||||
public class EnvironmentUtils {
|
||||
|
||||
private static final Environment environment = SpringContext.CONTEXT.getBean(Environment.class);
|
||||
public static final String DEFAULT_ENV = "default ";
|
||||
|
||||
/**
|
||||
@ -21,10 +21,14 @@ public class EnvironmentUtils {
|
||||
*/
|
||||
public static Boolean getLogStatus() {
|
||||
|
||||
Environment environment = SpringContext.CONTEXT.getBean(Environment.class);
|
||||
Environment environment = SpringContext.getBean(Environment.class);
|
||||
if (Objects.nonNull(environment)) {
|
||||
return environment.getProperty("easy.retry.log.status", Boolean.class, Boolean.TRUE);
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取环境
|
||||
*
|
||||
@ -32,6 +36,11 @@ public class EnvironmentUtils {
|
||||
*/
|
||||
public static String getActiveProfile() {
|
||||
|
||||
Environment environment = SpringContext.getBean(Environment.class);
|
||||
if (Objects.isNull(environment)) {
|
||||
return DEFAULT_ENV;
|
||||
}
|
||||
|
||||
String[] activeProfiles = environment.getActiveProfiles();
|
||||
if (activeProfiles.length == 0) {
|
||||
return DEFAULT_ENV;
|
||||
@ -39,7 +48,7 @@ public class EnvironmentUtils {
|
||||
|
||||
StringBuilder envs = new StringBuilder();
|
||||
for (String activeProfile : activeProfiles) {
|
||||
envs.append(activeProfile + " ");
|
||||
envs.append(activeProfile).append(" ");
|
||||
}
|
||||
return envs.toString();
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.aizuda.easy.retry.common.log;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aizuda.easy.retry.common.core.util.EnvironmentUtils;
|
||||
import com.aizuda.easy.retry.common.log.lang.LogCaller;
|
||||
import com.aizuda.easy.retry.common.log.level.Level;
|
||||
@ -63,7 +62,7 @@ public final class Local {
|
||||
return;
|
||||
}
|
||||
|
||||
debug(LogFactory.get(LogCaller.getCallerCaller()), format, false, arguments);
|
||||
debug(LogFactory.get(LogCaller.getCallerCaller()), format, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,7 +126,7 @@ public final class Local {
|
||||
return;
|
||||
}
|
||||
|
||||
warn(LogFactory.get(LogCaller.getCallerCaller()), format, false, arguments);
|
||||
warn(LogFactory.get(LogCaller.getCallerCaller()), format, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,7 +142,7 @@ public final class Local {
|
||||
return;
|
||||
}
|
||||
|
||||
warn(LogFactory.get(LogCaller.getCallerCaller()), e, StrUtil.format(format, arguments), false);
|
||||
warn(LogFactory.get(LogCaller.getCallerCaller()), e, format, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -235,7 +234,7 @@ public final class Local {
|
||||
return;
|
||||
}
|
||||
|
||||
error(log, e, e.getMessage(), false);
|
||||
error(log, e, e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -127,7 +127,7 @@ public final class Remote {
|
||||
return;
|
||||
}
|
||||
|
||||
warn(com.aizuda.easy.retry.common.log.LogFactory.get(LogCaller.getCallerCaller()), format, arguments);
|
||||
warn(LogFactory.get(LogCaller.getCallerCaller()), format, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,7 +143,7 @@ public final class Remote {
|
||||
return;
|
||||
}
|
||||
|
||||
warn(com.aizuda.easy.retry.common.log.LogFactory.get(LogCaller.getCallerCaller()), e, StrUtil.format(format, arguments));
|
||||
warn(LogFactory.get(LogCaller.getCallerCaller()), e, StrUtil.format(format, arguments));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -205,7 +205,7 @@ public final class Remote {
|
||||
return;
|
||||
}
|
||||
|
||||
error(com.aizuda.easy.retry.common.log.LogFactory.get(LogCaller.getCallerCaller()), format, arguments);
|
||||
error(LogFactory.get(LogCaller.getCallerCaller()), format, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,7 +221,7 @@ public final class Remote {
|
||||
return;
|
||||
}
|
||||
|
||||
error(com.aizuda.easy.retry.common.log.LogFactory.get(LogCaller.getCallerCaller()), e, format, arguments);
|
||||
error(LogFactory.get(LogCaller.getCallerCaller()), e, format, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -245,7 +245,7 @@ public final class Remote {
|
||||
* @param format 格式文本,{} 代表变量
|
||||
* @param arguments 变量对应的参数
|
||||
*/
|
||||
public void error(com.aizuda.easy.retry.common.log.Log log, String format, Object... arguments) {
|
||||
public void error(Log log, String format, Object... arguments) {
|
||||
if (!EnvironmentUtils.getLogStatus()) {
|
||||
return;
|
||||
}
|
||||
@ -261,7 +261,7 @@ public final class Remote {
|
||||
* @param format 格式文本,{} 代表变量
|
||||
* @param arguments 变量对应的参数
|
||||
*/
|
||||
public void error(com.aizuda.easy.retry.common.log.Log log, Throwable e, String format, Object... arguments) {
|
||||
public void error(Log log, Throwable e, String format, Object... arguments) {
|
||||
if (!EnvironmentUtils.getLogStatus()) {
|
||||
return;
|
||||
}
|
||||
@ -284,6 +284,6 @@ public final class Remote {
|
||||
return;
|
||||
}
|
||||
|
||||
com.aizuda.easy.retry.common.log.LogFactory.get(LogCaller.getCallerCaller()).log(FQCN, level, t, format, true, arguments);
|
||||
LogFactory.get(LogCaller.getCallerCaller()).log(FQCN, level, t, format, true, arguments);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user