mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
日志占位符忽略null值
This commit is contained in:
@@ -25,6 +25,7 @@ import com.yomahub.liteflow.enums.ExecuteTypeEnum;
|
||||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ChainEndException;
|
||||
import com.yomahub.liteflow.exception.FlowSystemException;
|
||||
import com.yomahub.liteflow.util.LogUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -126,7 +127,7 @@ public class Node implements Executable,Cloneable{
|
||||
if (instance.isAccess()) {
|
||||
//根据配置判断是否打印执行中的日志
|
||||
if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())){
|
||||
LOG.info("[{}]:[O]start component[{}] [{}] execution",slot.getRequestId(),instance.getClass().getSimpleName(),instance.getName());
|
||||
LogUtil.info(LOG,"[{}]:[O]start component[{}][{}] execution",slot.getRequestId(),instance.getClass().getSimpleName(),instance.getName());
|
||||
}
|
||||
|
||||
//这里开始进行重试的逻辑和主逻辑的运行
|
||||
@@ -140,7 +141,7 @@ public class Node implements Executable,Cloneable{
|
||||
}
|
||||
} else {
|
||||
if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())){
|
||||
LOG.info("[{}]:[X]skip component[{}] execution", slot.getRequestId(), instance.getClass().getSimpleName());
|
||||
LogUtil.info(LOG,"[{}]:[X]skip component[{}][{}] execution", slot.getRequestId(), instance.getClass().getSimpleName(),instance.getName());
|
||||
}
|
||||
}
|
||||
} catch (ChainEndException e){
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.yomahub.liteflow.util;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author 惊云
|
||||
* @date 2022/6/12 11:05
|
||||
*/
|
||||
public class LogUtil {
|
||||
|
||||
/**
|
||||
* 日志输出,过滤掉null值的占位符
|
||||
* @param logger
|
||||
* @param message
|
||||
* @param arguments
|
||||
*/
|
||||
public static void info(Logger logger,String message,Object... arguments){
|
||||
info(PlaceholderEnum.PACK_PLACEHOLDER,logger,message,arguments);
|
||||
}
|
||||
|
||||
public static void info(PlaceholderEnum placeholderEnum,Logger logger,String message,Object... arguments){
|
||||
StringBuilder result = new StringBuilder(message);
|
||||
int replaceCount = 0;
|
||||
for (int i = 0; i < arguments.length; i++){
|
||||
if(Objects.isNull(arguments[i])){
|
||||
int index = StringUtils.ordinalIndexOf(result.toString(), placeholderEnum.getValue(), i+1-replaceCount);
|
||||
if(index > 0){
|
||||
replaceCount++;
|
||||
result.replace(index,index + placeholderEnum.getValue().length(),"");
|
||||
}
|
||||
}
|
||||
}
|
||||
Object[] objects = Arrays.stream(arguments).filter(Objects::nonNull).toArray();
|
||||
logger.info(result.toString(),objects);
|
||||
}
|
||||
|
||||
public enum PlaceholderEnum{
|
||||
PLACEHOLDER("PLACEHOLDER","{}"),
|
||||
PACK_PLACEHOLDER("PACK_PLACEHOLDER", "[{}]");
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
PlaceholderEnum(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
private String getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
private String getValue(){
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// String a = StringUtils.replace("{}sda{}{}{}","{}","");
|
||||
// int i1 = StringUtils.ordinalIndexOf("1{}sda{}{}{}", "{}", 0);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user