mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 13:34:09 +08:00
fix comment
This commit is contained in:
parent
bb607e30ae
commit
6fda8f0244
@ -65,12 +65,21 @@ public class HighMultiReplacerV2 extends StrReplacer {
|
|||||||
* AC 自动机
|
* AC 自动机
|
||||||
*/
|
*/
|
||||||
protected static class AhoCorasickAutomaton extends MultiStrFinder{
|
protected static class AhoCorasickAutomaton extends MultiStrFinder{
|
||||||
|
/**
|
||||||
|
* 替换的字符串Map
|
||||||
|
*/
|
||||||
protected final Map<String,String> replaceMap;
|
protected final Map<String,String> replaceMap;
|
||||||
|
|
||||||
public AhoCorasickAutomaton(final Map<String,String> replaceMap){
|
public AhoCorasickAutomaton(final Map<String,String> replaceMap){
|
||||||
super(replaceMap.keySet());
|
super(replaceMap.keySet());
|
||||||
this.replaceMap = replaceMap;
|
this.replaceMap = replaceMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 替换
|
||||||
|
* @param text 文本
|
||||||
|
* @param stringBuilder {@link StringBuilder}
|
||||||
|
*/
|
||||||
public void replace(final CharSequence text, final StringBuilder stringBuilder){
|
public void replace(final CharSequence text, final StringBuilder stringBuilder){
|
||||||
Node currentNode = root;
|
Node currentNode = root;
|
||||||
// 临时字符串存储空间
|
// 临时字符串存储空间
|
||||||
|
@ -33,6 +33,6 @@ public class IssueI676ITTest {
|
|||||||
final JSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.readUtf8Str("issueI676IT.json"));
|
final JSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.readUtf8Str("issueI676IT.json"));
|
||||||
final String xmlStr = JSONXMLSerializer.toXml(jsonObject, null, (String) null);
|
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));
|
final String content = String.valueOf(XPathUtil.getByXPath("/page/orderItems[1]/content", XmlUtil.readXml(xmlStr), XPathConstants.STRING));
|
||||||
Assertions.assertEquals(content, "bar1");
|
Assertions.assertEquals("bar1", content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,15 +23,24 @@ import cn.hutool.v7.core.text.StrUtil;
|
|||||||
import cn.hutool.v7.log.AbstractLog;
|
import cn.hutool.v7.log.AbstractLog;
|
||||||
import cn.hutool.v7.log.level.Level;
|
import cn.hutool.v7.log.level.Level;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apache Commons Logging
|
* Apache Commons Logging
|
||||||
*
|
*
|
||||||
* @author Looly
|
* @author Looly
|
||||||
*/
|
*/
|
||||||
public class ApacheCommonsLog extends AbstractLog {
|
public class ApacheCommonsLog extends AbstractLog {
|
||||||
|
@Serial
|
||||||
private static final long serialVersionUID = -6843151523380063975L;
|
private static final long serialVersionUID = -6843151523380063975L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* logger
|
||||||
|
*/
|
||||||
private final transient Log logger;
|
private final transient Log logger;
|
||||||
|
/**
|
||||||
|
* 名称
|
||||||
|
*/
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------- Constructor
|
// ------------------------------------------------------------------------- Constructor
|
||||||
|
@ -24,17 +24,23 @@ import cn.hutool.v7.core.text.StrUtil;
|
|||||||
import cn.hutool.v7.log.AbstractLog;
|
import cn.hutool.v7.log.AbstractLog;
|
||||||
import cn.hutool.v7.log.level.Level;
|
import cn.hutool.v7.log.level.Level;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 利用System.out.println()打印日志
|
* 利用System.out.println()打印日志
|
||||||
*
|
*
|
||||||
* @author Looly
|
* @author Looly
|
||||||
*/
|
*/
|
||||||
public class ConsoleLog extends AbstractLog {
|
public class ConsoleLog extends AbstractLog {
|
||||||
|
@Serial
|
||||||
private static final long serialVersionUID = -6843151523380063975L;
|
private static final long serialVersionUID = -6843151523380063975L;
|
||||||
|
|
||||||
private static final String logFormat = "[{date}] [{level}] {name}: {msg}";
|
private static final String logFormat = "[{date}] [{level}] {name}: {msg}";
|
||||||
private static Level currentLevel = Level.DEBUG;
|
private static Level currentLevel = Level.DEBUG;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志名
|
||||||
|
*/
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
//------------------------------------------------------------------------- Constructor
|
//------------------------------------------------------------------------- Constructor
|
||||||
|
@ -16,37 +16,55 @@
|
|||||||
|
|
||||||
package cn.hutool.v7.log.engine.jdk;
|
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.Level;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
import java.util.logging.Logger;
|
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.
|
* <a href="http://java.sun.com/javase/6/docs/technotes/guides/logging/index.html">java.util.logging</a> log.
|
||||||
*
|
*
|
||||||
* @author Looly
|
* @author Looly
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class JdkLog extends AbstractLog {
|
public class JdkLog extends AbstractLog {
|
||||||
|
@Serial
|
||||||
private static final long serialVersionUID = -6843151523380063975L;
|
private static final long serialVersionUID = -6843151523380063975L;
|
||||||
|
|
||||||
private final transient Logger logger;
|
private final transient Logger logger;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------- Constructor
|
// ------------------------------------------------------------------------- Constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造函数,初始化JdkLog对象
|
||||||
|
*
|
||||||
|
* @param logger 日志记录器对象,用于记录日志信息
|
||||||
|
*/
|
||||||
public JdkLog(final Logger logger) {
|
public JdkLog(final Logger logger) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造函数,通过类对象初始化JdkLog对象
|
||||||
|
*
|
||||||
|
* @param clazz 类对象,用于创建日志记录器
|
||||||
|
*/
|
||||||
public JdkLog(final Class<?> clazz) {
|
public JdkLog(final Class<?> clazz) {
|
||||||
this((null == clazz) ? StrUtil.NULL : clazz.getName());
|
this((null == clazz) ? StrUtil.NULL : clazz.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造函数,通过日志记录器名称初始化JdkLog对象
|
||||||
|
*
|
||||||
|
* @param name 日志记录器的名称,用于创建日志记录器
|
||||||
|
*/
|
||||||
public JdkLog(final String name) {
|
public JdkLog(final String name) {
|
||||||
this(Logger.getLogger(name));
|
this(Logger.getLogger(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return logger.getName();
|
return logger.getName();
|
||||||
@ -110,41 +128,30 @@ public class JdkLog extends AbstractLog {
|
|||||||
// ------------------------------------------------------------------------- Log
|
// ------------------------------------------------------------------------- Log
|
||||||
@Override
|
@Override
|
||||||
public void log(final String fqcn, final cn.hutool.v7.log.level.Level level, final Throwable t, final String format, final Object... arguments) {
|
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;
|
final Level jdkLevel = switch (level) {
|
||||||
switch (level) {
|
case TRACE -> Level.FINEST;
|
||||||
case TRACE:
|
case DEBUG -> Level.FINE;
|
||||||
jdkLevel = Level.FINEST;
|
case INFO -> Level.INFO;
|
||||||
break;
|
case WARN -> Level.WARNING;
|
||||||
case DEBUG:
|
case ERROR -> Level.SEVERE;
|
||||||
jdkLevel = Level.FINE;
|
default -> throw new Error(StrUtil.format("Can not identify level: {}", level));
|
||||||
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));
|
|
||||||
}
|
|
||||||
logIfEnabled(fqcn, jdkLevel, t, format, arguments);
|
logIfEnabled(fqcn, jdkLevel, t, format, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------- Private method
|
// ------------------------------------------------------------------------- Private method
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打印对应等级的日志
|
* 打印对应等级的日志
|
||||||
*
|
*
|
||||||
* @param callerFQCN 调用者的完全限定类名(Fully Qualified Class Name)
|
* @param callerFQCN 调用者的完全限定类名(Fully Qualified Class Name)
|
||||||
* @param level 等级
|
* @param level 等级
|
||||||
* @param throwable 异常对象
|
* @param throwable 异常对象
|
||||||
* @param format 消息模板
|
* @param format 消息模板
|
||||||
* @param arguments 参数
|
* @param arguments 参数
|
||||||
*/
|
*/
|
||||||
private void logIfEnabled(final String callerFQCN, final Level level, final Throwable throwable, final String format, final Object[] arguments){
|
private void logIfEnabled(final String callerFQCN, final Level level, final Throwable throwable, final String format, final Object[] arguments) {
|
||||||
if(logger.isLoggable(level)){
|
if (logger.isLoggable(level)) {
|
||||||
final LogRecord record = new LogRecord(level, StrUtil.format(format, arguments));
|
final LogRecord record = new LogRecord(level, StrUtil.format(format, arguments));
|
||||||
record.setLoggerName(getName());
|
record.setLoggerName(getName());
|
||||||
record.setThrown(throwable);
|
record.setThrown(throwable);
|
||||||
@ -155,15 +162,16 @@ public class JdkLog extends AbstractLog {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 传入调用日志类的信息
|
* 传入调用日志类的信息
|
||||||
|
*
|
||||||
* @param callerFQCN 调用者全限定类名
|
* @param callerFQCN 调用者全限定类名
|
||||||
* @param record The record to update
|
* @param record The record to update
|
||||||
*/
|
*/
|
||||||
private static void fillCallerData(final String callerFQCN, final LogRecord record) {
|
private static void fillCallerData(final String callerFQCN, final LogRecord record) {
|
||||||
final StackTraceElement[] steArray = Thread.currentThread().getStackTrace();
|
final StackTraceElement[] steArray = Thread.currentThread().getStackTrace();
|
||||||
|
|
||||||
int found = -1;
|
int found = -1;
|
||||||
String className;
|
String className;
|
||||||
for (int i = steArray.length -2; i > -1; i--) {
|
for (int i = steArray.length - 2; i > -1; i--) {
|
||||||
// 此处初始值为length-2,表示从倒数第二个堆栈开始检查,如果是倒数第一个,那调用者就获取不到
|
// 此处初始值为length-2,表示从倒数第二个堆栈开始检查,如果是倒数第一个,那调用者就获取不到
|
||||||
className = steArray[i].getClassName();
|
className = steArray[i].getClassName();
|
||||||
if (callerFQCN.equals(className)) {
|
if (callerFQCN.equals(className)) {
|
||||||
@ -173,7 +181,7 @@ public class JdkLog extends AbstractLog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (found > -1) {
|
if (found > -1) {
|
||||||
final StackTraceElement ste = steArray[found+1];
|
final StackTraceElement ste = steArray[found + 1];
|
||||||
record.setSourceClassName(ste.getClassName());
|
record.setSourceClassName(ste.getClassName());
|
||||||
record.setSourceMethodName(ste.getMethodName());
|
record.setSourceMethodName(ste.getMethodName());
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@ import org.apache.logging.log4j.Level;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
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>
|
* <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 {
|
public class Log4jLog extends AbstractLog {
|
||||||
|
@Serial
|
||||||
private static final long serialVersionUID = -6843151523380063975L;
|
private static final long serialVersionUID = -6843151523380063975L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log4j的日志实现
|
||||||
|
*/
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------- Constructor
|
// ------------------------------------------------------------------------- Constructor
|
||||||
|
@ -26,28 +26,36 @@ import org.tinylog.format.MessageFormatter;
|
|||||||
import org.tinylog.provider.LoggingProvider;
|
import org.tinylog.provider.LoggingProvider;
|
||||||
import org.tinylog.provider.ProviderRegistry;
|
import org.tinylog.provider.ProviderRegistry;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <a href="http://www.tinylog.org/">tinylog</a> log.<br>
|
* <a href="http://www.tinylog.org/">tinylog</a> log.<br>
|
||||||
*
|
*
|
||||||
* @author Looly
|
* @author Looly
|
||||||
*/
|
*/
|
||||||
public class TinyLog extends AbstractLog {
|
public class TinyLog extends AbstractLog {
|
||||||
|
@Serial
|
||||||
private static final long serialVersionUID = -4848042277045993735L;
|
private static final long serialVersionUID = -4848042277045993735L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 堆栈增加层数,因为封装因此多了两层,此值用于正确获取当前类名
|
* 堆栈增加层数,因为封装因此多了两层,此值用于正确获取当前类名
|
||||||
*/
|
*/
|
||||||
private static final int DEPTH = 4;
|
private static final int DEPTH = 4;
|
||||||
|
|
||||||
private final int level;
|
|
||||||
private final String name;
|
|
||||||
private static final LoggingProvider provider = ProviderRegistry.getLoggingProvider();
|
private static final LoggingProvider provider = ProviderRegistry.getLoggingProvider();
|
||||||
|
|
||||||
private static final MessageFormatter formatter = new AdvancedMessageFormatter(
|
private static final MessageFormatter formatter = new AdvancedMessageFormatter(
|
||||||
Configuration.getLocale(),
|
Configuration.getLocale(),
|
||||||
Configuration.isEscapingEnabled()
|
Configuration.isEscapingEnabled()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志级别
|
||||||
|
*/
|
||||||
|
private final int level;
|
||||||
|
/**
|
||||||
|
* 日志名
|
||||||
|
*/
|
||||||
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
*
|
*
|
||||||
|
@ -26,29 +26,36 @@ import org.tinylog.format.MessageFormatter;
|
|||||||
import org.tinylog.provider.LoggingProvider;
|
import org.tinylog.provider.LoggingProvider;
|
||||||
import org.tinylog.provider.ProviderRegistry;
|
import org.tinylog.provider.ProviderRegistry;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <a href="http://www.tinylog.org/">tinylog</a> log.<br>
|
* <a href="http://www.tinylog.org/">tinylog</a> log.<br>
|
||||||
*
|
*
|
||||||
* @author Looly
|
* @author Looly
|
||||||
*/
|
*/
|
||||||
public class TinyLog2 extends AbstractLog {
|
public class TinyLog2 extends AbstractLog {
|
||||||
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 堆栈增加层数,因为封装因此多了两层,此值用于正确获取当前类名
|
* 堆栈增加层数,因为封装因此多了两层,此值用于正确获取当前类名
|
||||||
*/
|
*/
|
||||||
private static final int DEPTH = 5;
|
private static final int DEPTH = 5;
|
||||||
|
|
||||||
private final int level;
|
|
||||||
private final String name;
|
|
||||||
private static final LoggingProvider provider = ProviderRegistry.getLoggingProvider();
|
private static final LoggingProvider provider = ProviderRegistry.getLoggingProvider();
|
||||||
// ------------------------------------------------------------------------- Constructor
|
|
||||||
|
|
||||||
private static final MessageFormatter formatter = new AdvancedMessageFormatter(
|
private static final MessageFormatter formatter = new AdvancedMessageFormatter(
|
||||||
Configuration.getLocale(),
|
Configuration.getLocale(),
|
||||||
Configuration.isEscapingEnabled()
|
Configuration.isEscapingEnabled()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志级别
|
||||||
|
*/
|
||||||
|
private final int level;
|
||||||
|
/**
|
||||||
|
* 日志名称
|
||||||
|
*/
|
||||||
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
*
|
*
|
||||||
@ -165,30 +172,15 @@ public class TinyLog2 extends AbstractLog {
|
|||||||
* @since 4.0.3
|
* @since 4.0.3
|
||||||
*/
|
*/
|
||||||
private Level toTinyLevel(final cn.hutool.v7.log.level.Level level) {
|
private Level toTinyLevel(final cn.hutool.v7.log.level.Level level) {
|
||||||
final Level tinyLevel;
|
return switch (level) {
|
||||||
switch (level) {
|
case TRACE -> Level.TRACE;
|
||||||
case TRACE:
|
case DEBUG -> Level.DEBUG;
|
||||||
tinyLevel = Level.TRACE;
|
case INFO -> Level.INFO;
|
||||||
break;
|
case WARN -> Level.WARN;
|
||||||
case DEBUG:
|
case ERROR -> Level.ERROR;
|
||||||
tinyLevel = Level.DEBUG;
|
case OFF -> Level.OFF;
|
||||||
break;
|
default -> throw new Error(StrUtil.format("Can not identify level: {}", level));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user