添加 modul-info.java 暂未完成

This commit is contained in:
choweli
2025-04-18 17:22:55 +08:00
parent bedfa07a8a
commit 2a90c4b7b5
33 changed files with 948 additions and 28 deletions

View File

@@ -16,10 +16,9 @@
package cn.hutool.v7.log.engine.commons;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.Log4JLogger;
import cn.hutool.v7.log.engine.log4j.Log4jLog;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* Apache Commons Logging for Log4j
@@ -36,8 +35,8 @@ public class ApacheCommonsLog4JLog extends Log4jLog {
*
* @param logger Logger
*/
public ApacheCommonsLog4JLog(final Log logger) {
super(((Log4JLogger) logger).getLogger());
public ApacheCommonsLog4JLog(final Logger logger) {
super(logger);
}
/**
@@ -46,7 +45,7 @@ public class ApacheCommonsLog4JLog extends Log4jLog {
* @param clazz 类
*/
public ApacheCommonsLog4JLog(final Class<?> clazz) {
super(clazz);
super(LogManager.getLogger(clazz));
}
/**
@@ -55,6 +54,6 @@ public class ApacheCommonsLog4JLog extends Log4jLog {
* @param name 名称
*/
public ApacheCommonsLog4JLog(final String name) {
super(name);
super(LogManager.getLogger(name));
}
}

View File

@@ -16,11 +16,11 @@
package cn.hutool.v7.log.engine.log4j;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import cn.hutool.v7.core.text.StrUtil;
import cn.hutool.v7.log.AbstractLog;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* <a href="http://logging.apache.org/log4j/1.2/index.html">Apache Log4J</a> log.<br>
@@ -49,7 +49,7 @@ public class Log4jLog extends AbstractLog {
* @param name 日志标识
*/
public Log4jLog(final String name) {
this(Logger.getLogger(name));
this(LogManager.getLogger(name));
}
/**
@@ -101,7 +101,7 @@ public class Log4jLog extends AbstractLog {
// ------------------------------------------------------------------------- Warn
@Override
public boolean isWarnEnabled() {
return logger.isEnabledFor(Level.WARN);
return logger.isEnabled(Level.WARN);
}
@Override
@@ -112,7 +112,7 @@ public class Log4jLog extends AbstractLog {
// ------------------------------------------------------------------------- Error
@Override
public boolean isErrorEnabled() {
return logger.isEnabledFor(Level.ERROR);
return logger.isEnabled(Level.ERROR);
}
@Override
@@ -144,8 +144,9 @@ public class Log4jLog extends AbstractLog {
throw new Error(StrUtil.format("Can not identify level: {}", level));
}
if(logger.isEnabledFor(log4jLevel)) {
logger.log(fqcn, log4jLevel, StrUtil.format(format, arguments), t);
if(logger.isEnabled(log4jLevel)) {
//Log4j2的API设计已内置类名自动获取能力
logger.log(log4jLevel, StrUtil.format(format, arguments), t);
}
}
}

View File

@@ -16,13 +16,15 @@
package cn.hutool.v7.log.engine.tinylog;
import cn.hutool.v7.log.AbstractLog;
import org.pmw.tinylog.Level;
import org.pmw.tinylog.LogEntryForwarder;
import org.pmw.tinylog.Logger;
import cn.hutool.v7.core.array.ArrayUtil;
import cn.hutool.v7.core.text.StrUtil;
import cn.hutool.v7.log.AbstractLog;
import org.tinylog.Level;
import org.tinylog.configuration.Configuration;
import org.tinylog.format.AdvancedMessageFormatter;
import org.tinylog.format.MessageFormatter;
import org.tinylog.provider.LoggingProvider;
import org.tinylog.provider.ProviderRegistry;
/**
* <a href="http://www.tinylog.org/">tinylog</a> log.<br>
@@ -39,6 +41,12 @@ public class TinyLog extends AbstractLog {
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()
);
/**
* 构造
@@ -57,7 +65,7 @@ public class TinyLog extends AbstractLog {
*/
public TinyLog(final String name) {
this.name = name;
this.level = Logger.getLevel(name).ordinal();
this.level = provider.getMinimumLevel().ordinal();
}
@Override
@@ -101,12 +109,12 @@ public class TinyLog extends AbstractLog {
// ------------------------------------------------------------------------- Warn
@Override
public boolean isWarnEnabled() {
return this.level <= org.pmw.tinylog.Level.WARNING.ordinal();
return this.level <= Level.WARN.ordinal();
}
@Override
public void warn(final String fqcn, final Throwable t, final String format, final Object... arguments) {
logIfEnabled(fqcn, Level.WARNING, t, format, arguments);
logIfEnabled(fqcn, Level.WARN, t, format, arguments);
}
// ------------------------------------------------------------------------- Error
@@ -145,7 +153,7 @@ public class TinyLog extends AbstractLog {
if (null == t) {
t = getLastArgumentIfThrowable(arguments);
}
LogEntryForwarder.forward(DEPTH, level, t, StrUtil.toString(format), arguments);
provider.log(DEPTH, null, level, t, formatter, StrUtil.toString(format), arguments);
}
/**
@@ -168,7 +176,7 @@ public class TinyLog extends AbstractLog {
tinyLevel = Level.INFO;
break;
case WARN:
tinyLevel = Level.WARNING;
tinyLevel = Level.WARN;
break;
case ERROR:
tinyLevel = Level.ERROR;

View File

@@ -32,7 +32,7 @@ public class TinyLogEngine extends AbsLogEngine {
*/
public TinyLogEngine() {
super("TinyLog");
checkLogExist(org.pmw.tinylog.Logger.class);
checkLogExist(org.tinylog.Logger.class);
}
@Override

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2025 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
* @author choweli
*/
module hutool.log {
exports cn.hutool.v7.log;
exports cn.hutool.v7.log.level;
exports cn.hutool.v7.log.engine.console;
exports cn.hutool.v7.log.engine.log4j2;
requires hutool.core;
requires org.jboss.logging;
requires org.apache.commons.logging;
requires org.apache.logging.log4j;
requires org.slf4j;
requires tinylog;
requires org.tinylog.api;
requires java.logging;
requires log4j;
}