mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -9,8 +9,8 @@ import cn.hutool.log.level.Level;
|
||||
|
||||
/**
|
||||
* Apache Commons Logging
|
||||
* @author Looly
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class ApacheCommonsLog extends AbstractLog {
|
||||
private static final long serialVersionUID = -6843151523380063975L;
|
||||
@@ -19,15 +19,32 @@ public class ApacheCommonsLog extends AbstractLog {
|
||||
private final String name;
|
||||
|
||||
// ------------------------------------------------------------------------- Constructor
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param logger Logger
|
||||
* @param name 名称
|
||||
*/
|
||||
public ApacheCommonsLog(final Log logger, final String name) {
|
||||
this.logger = logger;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param clazz 类
|
||||
*/
|
||||
public ApacheCommonsLog(final Class<?> clazz) {
|
||||
this(LogFactory.getLog(clazz), null == clazz ? StrUtil.NULL : clazz.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param name 名称
|
||||
*/
|
||||
public ApacheCommonsLog(final String name) {
|
||||
this(LogFactory.getLog(name), name);
|
||||
}
|
||||
@@ -46,7 +63,7 @@ public class ApacheCommonsLog extends AbstractLog {
|
||||
@Override
|
||||
public void trace(final String fqcn, final Throwable t, final String format, final Object... arguments) {
|
||||
// fqcn此处无效
|
||||
if(isTraceEnabled()){
|
||||
if (isTraceEnabled()) {
|
||||
logger.trace(StrUtil.format(format, arguments), t);
|
||||
}
|
||||
}
|
||||
@@ -60,7 +77,7 @@ public class ApacheCommonsLog extends AbstractLog {
|
||||
@Override
|
||||
public void debug(final String fqcn, final Throwable t, final String format, final Object... arguments) {
|
||||
// fqcn此处无效
|
||||
if(isDebugEnabled()){
|
||||
if (isDebugEnabled()) {
|
||||
logger.debug(StrUtil.format(format, arguments), t);
|
||||
}
|
||||
}
|
||||
@@ -74,7 +91,7 @@ public class ApacheCommonsLog extends AbstractLog {
|
||||
@Override
|
||||
public void info(final String fqcn, final Throwable t, final String format, final Object... arguments) {
|
||||
// fqcn此处无效
|
||||
if(isInfoEnabled()){
|
||||
if (isInfoEnabled()) {
|
||||
logger.info(StrUtil.format(format, arguments), t);
|
||||
}
|
||||
}
|
||||
@@ -87,7 +104,7 @@ public class ApacheCommonsLog extends AbstractLog {
|
||||
|
||||
@Override
|
||||
public void warn(final String format, final Object... arguments) {
|
||||
if(isWarnEnabled()){
|
||||
if (isWarnEnabled()) {
|
||||
logger.warn(StrUtil.format(format, arguments));
|
||||
}
|
||||
}
|
||||
@@ -99,7 +116,7 @@ public class ApacheCommonsLog extends AbstractLog {
|
||||
@Override
|
||||
public void warn(final String fqcn, final Throwable t, final String format, final Object... arguments) {
|
||||
// fqcn此处无效
|
||||
if(isWarnEnabled()){
|
||||
if (isWarnEnabled()) {
|
||||
logger.warn(StrUtil.format(format, arguments), t);
|
||||
}
|
||||
}
|
||||
@@ -113,7 +130,7 @@ public class ApacheCommonsLog extends AbstractLog {
|
||||
@Override
|
||||
public void error(final String fqcn, final Throwable t, final String format, final Object... arguments) {
|
||||
// fqcn此处无效
|
||||
if(isErrorEnabled()){
|
||||
if (isErrorEnabled()) {
|
||||
logger.warn(StrUtil.format(format, arguments), t);
|
||||
}
|
||||
|
||||
@@ -123,23 +140,23 @@ public class ApacheCommonsLog extends AbstractLog {
|
||||
@Override
|
||||
public void log(final String fqcn, final Level level, final Throwable t, final String format, final Object... arguments) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
trace(t, format, arguments);
|
||||
break;
|
||||
case DEBUG:
|
||||
debug(t, format, arguments);
|
||||
break;
|
||||
case INFO:
|
||||
info(t, format, arguments);
|
||||
break;
|
||||
case WARN:
|
||||
warn(t, format, arguments);
|
||||
break;
|
||||
case ERROR:
|
||||
error(t, format, arguments);
|
||||
break;
|
||||
default:
|
||||
throw new Error(StrUtil.format("Can not identify level: {}", level));
|
||||
case TRACE:
|
||||
trace(t, format, arguments);
|
||||
break;
|
||||
case DEBUG:
|
||||
debug(t, format, arguments);
|
||||
break;
|
||||
case INFO:
|
||||
info(t, format, arguments);
|
||||
break;
|
||||
case WARN:
|
||||
warn(t, format, arguments);
|
||||
break;
|
||||
case ERROR:
|
||||
error(t, format, arguments);
|
||||
break;
|
||||
default:
|
||||
throw new Error(StrUtil.format("Can not identify level: {}", level));
|
||||
}
|
||||
}
|
||||
// ------------------------------------------------------------------------- Private method
|
||||
|
@@ -7,21 +7,37 @@ import cn.hutool.log.dialect.log4j.Log4jLog;
|
||||
|
||||
/**
|
||||
* Apache Commons Logging for Log4j
|
||||
* @author Looly
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class ApacheCommonsLog4JLog extends Log4jLog {
|
||||
private static final long serialVersionUID = -6843151523380063975L;
|
||||
|
||||
// ------------------------------------------------------------------------- Constructor
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param logger Logger
|
||||
*/
|
||||
public ApacheCommonsLog4JLog(final Log logger) {
|
||||
super(((Log4JLogger) logger).getLogger());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param clazz 类
|
||||
*/
|
||||
public ApacheCommonsLog4JLog(final Class<?> clazz) {
|
||||
super(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param name 名称
|
||||
*/
|
||||
public ApacheCommonsLog4JLog(final String name) {
|
||||
super(name);
|
||||
}
|
||||
|
@@ -10,6 +10,9 @@ import cn.hutool.log.LogFactory;
|
||||
*/
|
||||
public class ApacheCommonsLogFactory extends LogFactory{
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public ApacheCommonsLogFactory() {
|
||||
super("Apache Common Logging");
|
||||
checkLogExist(org.apache.commons.logging.LogFactory.class);
|
||||
|
@@ -14,12 +14,13 @@ import org.tinylog.provider.ProviderRegistry;
|
||||
* <a href="http://www.tinylog.org/">tinylog</a> log.<br>
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public class TinyLog2 extends AbstractLog {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 堆栈增加层数,因为封装因此多了两层,此值用于正确获取当前类名 */
|
||||
/**
|
||||
* 堆栈增加层数,因为封装因此多了两层,此值用于正确获取当前类名
|
||||
*/
|
||||
private static final int DEPTH = 5;
|
||||
|
||||
private final int level;
|
||||
@@ -31,10 +32,21 @@ public class TinyLog2 extends AbstractLog {
|
||||
Configuration.getLocale(),
|
||||
Configuration.isEscapingEnabled()
|
||||
);
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param clazz class
|
||||
*/
|
||||
public TinyLog2(final Class<?> clazz) {
|
||||
this(null == clazz ? StrUtil.NULL : clazz.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param name 名称
|
||||
*/
|
||||
public TinyLog2(final String name) {
|
||||
this.name = name;
|
||||
this.level = provider.getMinimumLevel().ordinal();
|
||||
@@ -66,6 +78,7 @@ public class TinyLog2 extends AbstractLog {
|
||||
public void debug(final String fqcn, final Throwable t, final String format, final Object... arguments) {
|
||||
logIfEnabled(fqcn, Level.DEBUG, t, format, arguments);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------- Info
|
||||
@Override
|
||||
public boolean isInfoEnabled() {
|
||||
@@ -112,15 +125,17 @@ public class TinyLog2 extends AbstractLog {
|
||||
|
||||
/**
|
||||
* 在对应日志级别打开情况下打印日志
|
||||
* @param fqcn 完全限定类名(Fully Qualified Class Name),用于定位日志位置
|
||||
* @param level 日志级别
|
||||
* @param t 异常,null则检查最后一个参数是否为Throwable类型,是则取之,否则不打印堆栈
|
||||
* @param format 日志消息模板
|
||||
*
|
||||
* @param fqcn 完全限定类名(Fully Qualified Class Name),用于定位日志位置
|
||||
* @param level 日志级别
|
||||
* @param t 异常,null则检查最后一个参数是否为Throwable类型,是则取之,否则不打印堆栈
|
||||
* @param format 日志消息模板
|
||||
* @param arguments 日志消息参数
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private void logIfEnabled(final String fqcn, final Level level, Throwable t, final String format, final Object... arguments) {
|
||||
// fqcn 无效
|
||||
if(null == t){
|
||||
if (null == t) {
|
||||
t = getLastArgumentIfThrowable(arguments);
|
||||
}
|
||||
provider.log(DEPTH, null, level, t, formatter, StrUtil.toString(format), arguments);
|
||||
@@ -136,26 +151,26 @@ public class TinyLog2 extends AbstractLog {
|
||||
private Level toTinyLevel(final cn.hutool.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));
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user