升级日志
This commit is contained in:
parent
73a7d95129
commit
70a05e23c3
|
|
@ -1,33 +1,81 @@
|
|||
package com.electromagnetic.industry.software.common.util;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class EleLog {
|
||||
|
||||
private static final String PLACE_HOLDER = "{}";
|
||||
|
||||
private Logger logger;
|
||||
|
||||
public EleLog(Class clazz) {
|
||||
this.logger = LoggerFactory.getLogger(clazz);
|
||||
}
|
||||
|
||||
public void info(String msg) {
|
||||
logger.info(msg);
|
||||
public void info(String msg, Object... args) {
|
||||
logger.info(format(msg, args));
|
||||
}
|
||||
|
||||
public void debug(String msg) {
|
||||
logger.debug(msg);
|
||||
public void debug(String msg, Object... args) {
|
||||
logger.debug(format(msg, args));
|
||||
}
|
||||
|
||||
public void warn(String msg) {
|
||||
logger.warn(msg);
|
||||
public void warn(String msg, Object... args) {
|
||||
logger.warn(format(msg, args));
|
||||
}
|
||||
|
||||
public void error(String msg) {
|
||||
logger.error(msg);
|
||||
public void error(String msg, Object... args) {
|
||||
logger.error(format(msg, args));
|
||||
}
|
||||
|
||||
public void error(String msg, Throwable e) {
|
||||
logger.error(msg, e);
|
||||
public void error(String msg, Throwable e, Object... args) {
|
||||
String info = format(msg, args);
|
||||
logger.error(info, e);
|
||||
}
|
||||
|
||||
private static String format(String strPattern, Object... argArray) {
|
||||
if (!StrUtil.isBlank(strPattern) && !StrUtil.isBlank(PLACE_HOLDER) && !ArrayUtil.isEmpty(argArray)) {
|
||||
int strPatternLength = strPattern.length();
|
||||
int placeHolderLength = PLACE_HOLDER.length();
|
||||
StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
|
||||
int handledPosition = 0;
|
||||
|
||||
for(int argIndex = 0; argIndex < argArray.length; ++argIndex) {
|
||||
int delimIndex = strPattern.indexOf(PLACE_HOLDER, handledPosition);
|
||||
if (delimIndex == -1) {
|
||||
if (handledPosition == 0) {
|
||||
return strPattern;
|
||||
}
|
||||
|
||||
sbuf.append(strPattern, handledPosition, strPatternLength);
|
||||
return sbuf.toString();
|
||||
}
|
||||
|
||||
if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == '\\') {
|
||||
if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == '\\') {
|
||||
sbuf.append(strPattern, handledPosition, delimIndex - 1);
|
||||
sbuf.append(StrUtil.utf8Str(argArray[argIndex]));
|
||||
handledPosition = delimIndex + placeHolderLength;
|
||||
} else {
|
||||
--argIndex;
|
||||
sbuf.append(strPattern, handledPosition, delimIndex - 1);
|
||||
sbuf.append(PLACE_HOLDER.charAt(0));
|
||||
handledPosition = delimIndex + 1;
|
||||
}
|
||||
} else {
|
||||
sbuf.append(strPattern, handledPosition, delimIndex);
|
||||
sbuf.append(StrUtil.utf8Str(argArray[argIndex]));
|
||||
handledPosition = delimIndex + placeHolderLength;
|
||||
}
|
||||
}
|
||||
|
||||
sbuf.append(strPattern, handledPosition, strPatternLength);
|
||||
return sbuf.toString();
|
||||
} else {
|
||||
return strPattern;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue