fix comment

This commit is contained in:
Looly 2025-06-25 17:44:06 +08:00
parent bb607e30ae
commit 6fda8f0244
8 changed files with 107 additions and 69 deletions

View File

@ -65,12 +65,21 @@ public class HighMultiReplacerV2 extends StrReplacer {
* AC 自动机
*/
protected static class AhoCorasickAutomaton extends MultiStrFinder{
/**
* 替换的字符串Map
*/
protected final Map<String,String> replaceMap;
public AhoCorasickAutomaton(final Map<String,String> replaceMap){
super(replaceMap.keySet());
this.replaceMap = replaceMap;
}
/**
* 替换
* @param text 文本
* @param stringBuilder {@link StringBuilder}
*/
public void replace(final CharSequence text, final StringBuilder stringBuilder){
Node currentNode = root;
// 临时字符串存储空间

View File

@ -33,6 +33,6 @@ public class IssueI676ITTest {
final JSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.readUtf8Str("issueI676IT.json"));
final String xmlStr = JSONXMLSerializer.toXml(jsonObject, null, (String) null);
final String content = String.valueOf(XPathUtil.getByXPath("/page/orderItems[1]/content", XmlUtil.readXml(xmlStr), XPathConstants.STRING));
Assertions.assertEquals(content, "bar1");
Assertions.assertEquals("bar1", content);
}
}

View File

@ -23,15 +23,24 @@ import cn.hutool.v7.core.text.StrUtil;
import cn.hutool.v7.log.AbstractLog;
import cn.hutool.v7.log.level.Level;
import java.io.Serial;
/**
* Apache Commons Logging
*
* @author Looly
*/
public class ApacheCommonsLog extends AbstractLog {
@Serial
private static final long serialVersionUID = -6843151523380063975L;
/**
* logger
*/
private final transient Log logger;
/**
* 名称
*/
private final String name;
// ------------------------------------------------------------------------- Constructor

View File

@ -24,17 +24,23 @@ import cn.hutool.v7.core.text.StrUtil;
import cn.hutool.v7.log.AbstractLog;
import cn.hutool.v7.log.level.Level;
import java.io.Serial;
/**
* 利用System.out.println()打印日志
*
* @author Looly
*/
public class ConsoleLog extends AbstractLog {
@Serial
private static final long serialVersionUID = -6843151523380063975L;
private static final String logFormat = "[{date}] [{level}] {name}: {msg}";
private static Level currentLevel = Level.DEBUG;
/**
* 日志名
*/
private final String name;
//------------------------------------------------------------------------- Constructor

View File

@ -16,37 +16,55 @@
package cn.hutool.v7.log.engine.jdk;
import cn.hutool.v7.core.text.StrUtil;
import cn.hutool.v7.log.AbstractLog;
import java.io.Serial;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import cn.hutool.v7.core.text.StrUtil;
import cn.hutool.v7.log.AbstractLog;
/**
* <a href="http://java.sun.com/javase/6/docs/technotes/guides/logging/index.html">java.util.logging</a> log.
*
* @author Looly
*
*/
public class JdkLog extends AbstractLog {
@Serial
private static final long serialVersionUID = -6843151523380063975L;
private final transient Logger logger;
// ------------------------------------------------------------------------- Constructor
/**
* 构造函数初始化JdkLog对象
*
* @param logger 日志记录器对象用于记录日志信息
*/
public JdkLog(final Logger logger) {
this.logger = logger;
}
/**
* 构造函数通过类对象初始化JdkLog对象
*
* @param clazz 类对象用于创建日志记录器
*/
public JdkLog(final Class<?> clazz) {
this((null == clazz) ? StrUtil.NULL : clazz.getName());
}
/**
* 构造函数通过日志记录器名称初始化JdkLog对象
*
* @param name 日志记录器的名称用于创建日志记录器
*/
public JdkLog(final String name) {
this(Logger.getLogger(name));
}
@Override
public String getName() {
return logger.getName();
@ -110,41 +128,30 @@ public class JdkLog extends AbstractLog {
// ------------------------------------------------------------------------- Log
@Override
public void log(final String fqcn, final cn.hutool.v7.log.level.Level level, final Throwable t, final String format, final Object... arguments) {
final Level jdkLevel;
switch (level) {
case TRACE:
jdkLevel = Level.FINEST;
break;
case DEBUG:
jdkLevel = Level.FINE;
break;
case INFO:
jdkLevel = Level.INFO;
break;
case WARN:
jdkLevel = Level.WARNING;
break;
case ERROR:
jdkLevel = Level.SEVERE;
break;
default:
throw new Error(StrUtil.format("Can not identify level: {}", level));
}
final Level jdkLevel = switch (level) {
case TRACE -> Level.FINEST;
case DEBUG -> Level.FINE;
case INFO -> Level.INFO;
case WARN -> Level.WARNING;
case ERROR -> Level.SEVERE;
default -> throw new Error(StrUtil.format("Can not identify level: {}", level));
};
logIfEnabled(fqcn, jdkLevel, t, format, arguments);
}
// ------------------------------------------------------------------------- Private method
/**
* 打印对应等级的日志
*
* @param callerFQCN 调用者的完全限定类名(Fully Qualified Class Name)
* @param level 等级
* @param throwable 异常对象
* @param format 消息模板
* @param arguments 参数
* @param level 等级
* @param throwable 异常对象
* @param format 消息模板
* @param arguments 参数
*/
private void logIfEnabled(final String callerFQCN, final Level level, final Throwable throwable, final String format, final Object[] arguments){
if(logger.isLoggable(level)){
private void logIfEnabled(final String callerFQCN, final Level level, final Throwable throwable, final String format, final Object[] arguments) {
if (logger.isLoggable(level)) {
final LogRecord record = new LogRecord(level, StrUtil.format(format, arguments));
record.setLoggerName(getName());
record.setThrown(throwable);
@ -155,15 +162,16 @@ public class JdkLog extends AbstractLog {
/**
* 传入调用日志类的信息
*
* @param callerFQCN 调用者全限定类名
* @param record The record to update
* @param record The record to update
*/
private static void fillCallerData(final String callerFQCN, final LogRecord record) {
final StackTraceElement[] steArray = Thread.currentThread().getStackTrace();
int found = -1;
String className;
for (int i = steArray.length -2; i > -1; i--) {
for (int i = steArray.length - 2; i > -1; i--) {
// 此处初始值为length-2表示从倒数第二个堆栈开始检查如果是倒数第一个那调用者就获取不到
className = steArray[i].getClassName();
if (callerFQCN.equals(className)) {
@ -173,7 +181,7 @@ public class JdkLog extends AbstractLog {
}
if (found > -1) {
final StackTraceElement ste = steArray[found+1];
final StackTraceElement ste = steArray[found + 1];
record.setSourceClassName(ste.getClassName());
record.setSourceMethodName(ste.getMethodName());
}

View File

@ -22,6 +22,8 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.Serial;
/**
* <a href="http://logging.apache.org/log4j/1.2/index.html">Apache Log4J</a> log.<br>
*
@ -29,8 +31,12 @@ import org.apache.logging.log4j.Logger;
*
*/
public class Log4jLog extends AbstractLog {
@Serial
private static final long serialVersionUID = -6843151523380063975L;
/**
* Log4j的日志实现
*/
private final Logger logger;
// ------------------------------------------------------------------------- Constructor

View File

@ -26,28 +26,36 @@ import org.tinylog.format.MessageFormatter;
import org.tinylog.provider.LoggingProvider;
import org.tinylog.provider.ProviderRegistry;
import java.io.Serial;
/**
* <a href="http://www.tinylog.org/">tinylog</a> log.<br>
*
* @author Looly
*/
public class TinyLog extends AbstractLog {
@Serial
private static final long serialVersionUID = -4848042277045993735L;
/**
* 堆栈增加层数因为封装因此多了两层此值用于正确获取当前类名
*/
private static final int DEPTH = 4;
private final int level;
private final String name;
private static final LoggingProvider provider = ProviderRegistry.getLoggingProvider();
private static final MessageFormatter formatter = new AdvancedMessageFormatter(
Configuration.getLocale(),
Configuration.isEscapingEnabled()
);
/**
* 日志级别
*/
private final int level;
/**
* 日志名
*/
private final String name;
/**
* 构造
*

View File

@ -26,29 +26,36 @@ import org.tinylog.format.MessageFormatter;
import org.tinylog.provider.LoggingProvider;
import org.tinylog.provider.ProviderRegistry;
import java.io.Serial;
/**
* <a href="http://www.tinylog.org/">tinylog</a> log.<br>
*
* @author Looly
*/
public class TinyLog2 extends AbstractLog {
@Serial
private static final long serialVersionUID = 1L;
/**
* 堆栈增加层数因为封装因此多了两层此值用于正确获取当前类名
*/
private static final int DEPTH = 5;
private final int level;
private final String name;
private static final LoggingProvider provider = ProviderRegistry.getLoggingProvider();
// ------------------------------------------------------------------------- Constructor
private static final MessageFormatter formatter = new AdvancedMessageFormatter(
Configuration.getLocale(),
Configuration.isEscapingEnabled()
Configuration.getLocale(),
Configuration.isEscapingEnabled()
);
/**
* 日志级别
*/
private final int level;
/**
* 日志名称
*/
private final String name;
/**
* 构造
*
@ -165,30 +172,15 @@ public class TinyLog2 extends AbstractLog {
* @since 4.0.3
*/
private Level toTinyLevel(final cn.hutool.v7.log.level.Level level) {
final Level tinyLevel;
switch (level) {
case TRACE:
tinyLevel = Level.TRACE;
break;
case DEBUG:
tinyLevel = Level.DEBUG;
break;
case INFO:
tinyLevel = Level.INFO;
break;
case WARN:
tinyLevel = Level.WARN;
break;
case ERROR:
tinyLevel = Level.ERROR;
break;
case OFF:
tinyLevel = Level.OFF;
break;
default:
throw new Error(StrUtil.format("Can not identify level: {}", level));
}
return tinyLevel;
return switch (level) {
case TRACE -> Level.TRACE;
case DEBUG -> Level.DEBUG;
case INFO -> Level.INFO;
case WARN -> Level.WARN;
case ERROR -> Level.ERROR;
case OFF -> Level.OFF;
default -> throw new Error(StrUtil.format("Can not identify level: {}", level));
};
}
/**