diff --git a/client/src/main/java/com/alibaba/nacos/client/logger/LoggerFactory.java b/client/src/main/java/com/alibaba/nacos/client/logger/LoggerFactory.java
index bc421aca797..2de5eee6ee7 100644
--- a/client/src/main/java/com/alibaba/nacos/client/logger/LoggerFactory.java
+++ b/client/src/main/java/com/alibaba/nacos/client/logger/LoggerFactory.java
@@ -15,16 +15,15 @@
*/
package com.alibaba.nacos.client.logger;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import com.alibaba.nacos.client.logger.log4j.Log4jLoggerFactory;
import com.alibaba.nacos.client.logger.log4j2.Log4j2LoggerFactory;
import com.alibaba.nacos.client.logger.nop.NopLoggerFactory;
import com.alibaba.nacos.client.logger.slf4j.Slf4jLoggerFactory;
import com.alibaba.nacos.client.logger.support.ILoggerFactory;
import com.alibaba.nacos.client.logger.support.LogLog;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
/**
*
* 阿里中间件LoggerFactory,获取具体日志实现
@@ -57,17 +56,12 @@ private LoggerFactory() {
LogLog.info("Init JM logger with Slf4jLoggerFactory success, " + LoggerFactory.class.getClassLoader());
} catch (Throwable e1) {
try {
- setLoggerFactory(new Log4jLoggerFactory());
- LogLog.info("Init JM logger with Log4jLoggerFactory, " + LoggerFactory.class.getClassLoader());
+ setLoggerFactory(new Log4j2LoggerFactory());
+ LogLog.info("Init JM logger with Log4j2LoggerFactory, " + LoggerFactory.class.getClassLoader());
} catch (Throwable e2) {
- try {
- setLoggerFactory(new Log4j2LoggerFactory());
- LogLog.info("Init JM logger with Log4j2LoggerFactory, " + LoggerFactory.class.getClassLoader());
- } catch (Throwable e3) {
- setLoggerFactory(new NopLoggerFactory());
- LogLog.warn("Init JM logger with NopLoggerFactory, pay attention. "
- + LoggerFactory.class.getClassLoader(), e2);
- }
+ setLoggerFactory(new NopLoggerFactory());
+ LogLog.warn("Init JM logger with NopLoggerFactory, pay attention. "
+ + LoggerFactory.class.getClassLoader(), e2);
}
}
diff --git a/client/src/main/java/com/alibaba/nacos/client/logger/log4j/Log4jLogger.java b/client/src/main/java/com/alibaba/nacos/client/logger/log4j/Log4jLogger.java
deleted file mode 100644
index 04389b494d2..00000000000
--- a/client/src/main/java/com/alibaba/nacos/client/logger/log4j/Log4jLogger.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright 1999-2018 Alibaba Group Holding Ltd.
- *
- * 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.
- */
-package com.alibaba.nacos.client.logger.log4j;
-
-import org.apache.log4j.Level;
-
-import com.alibaba.nacos.client.logger.Logger;
-import com.alibaba.nacos.client.logger.option.Log4jActivateOption;
-import com.alibaba.nacos.client.logger.support.LoggerHelper;
-import com.alibaba.nacos.client.logger.support.LoggerSupport;
-import com.alibaba.nacos.client.logger.util.MessageUtil;
-
-
-/**
- * Log4jLogger
- * @author Nacos
- *
- */
-public class Log4jLogger extends LoggerSupport implements Logger {
-
- private org.apache.log4j.Logger delegate;
-
- public Log4jLogger(org.apache.log4j.Logger delegate) {
- super(delegate);
-
- if (delegate == null) {
- throw new IllegalArgumentException("delegate Logger is null");
- }
- this.delegate = delegate;
-
- this.activateOption = new Log4jActivateOption(delegate);
- }
-
- @Override
- public void debug(String context, String message) {
- if (isDebugEnabled()) {
- message = LoggerHelper.getResourceBundleString(getProductName(), message);
- delegate.debug(MessageUtil.getMessage(context, message));
- }
- }
-
- @Override
- public void debug(String context, String format, Object... args) {
- if (isDebugEnabled()) {
- format = LoggerHelper.getResourceBundleString(getProductName(), format);
- delegate.debug(MessageUtil.getMessage(context, MessageUtil.formatMessage(format, args)));
- }
- }
-
- @Override
- public void info(String context, String message) {
- if (isInfoEnabled()) {
- message = LoggerHelper.getResourceBundleString(getProductName(), message);
- delegate.info(MessageUtil.getMessage(context, message));
- }
- }
-
- @Override
- public void info(String context, String format, Object... args) {
- if (isInfoEnabled()) {
- format = LoggerHelper.getResourceBundleString(getProductName(), format);
- delegate.info(MessageUtil.getMessage(context, MessageUtil.formatMessage(format, args)));
- }
- }
-
- @Override
- public void warn(String message, Throwable t) {
- if (isWarnEnabled()) {
- message = LoggerHelper.getResourceBundleString(getProductName(), message);
- delegate.warn(MessageUtil.getMessage(null, message), t);
- }
- }
-
- @Override
- public void warn(String context, String message) {
- if (isWarnEnabled()) {
- message = LoggerHelper.getResourceBundleString(getProductName(), message);
- delegate.warn(MessageUtil.getMessage(context, message));
- }
- }
-
- @Override
- public void warn(String context, String format, Object... args) {
- if (isWarnEnabled()) {
- format = LoggerHelper.getResourceBundleString(getProductName(), format);
- delegate.warn(MessageUtil.getMessage(context, MessageUtil.formatMessage(format, args)));
- }
- }
-
- @Override
- public void error(String context, String errorCode, String message) {
- if (isErrorEnabled()) {
- message = LoggerHelper.getResourceBundleString(getProductName(), message);
- delegate.error(MessageUtil.getMessage(context, errorCode, message));
- }
- }
-
- @Override
- public void error(String context, String errorCode, String message, Throwable t) {
- if (isErrorEnabled()) {
- message = LoggerHelper.getResourceBundleString(getProductName(), message);
- delegate.error(MessageUtil.getMessage(context, errorCode, message), t);
- }
- }
-
- @Override
- public void error(String context, String errorCode, String format, Object... args) {
- if (isErrorEnabled()) {
- format = LoggerHelper.getResourceBundleString(getProductName(), format);
- delegate.error(MessageUtil.getMessage(context, errorCode, MessageUtil.formatMessage(format, args)));
- }
- }
-
- @Override
- public boolean isDebugEnabled() {
- return delegate.isDebugEnabled();
- }
-
- @Override
- public boolean isInfoEnabled() {
- return delegate.isInfoEnabled();
- }
-
- @Override
- public boolean isWarnEnabled() {
- return delegate.isEnabledFor(Level.WARN);
- }
-
- @Override
- public boolean isErrorEnabled() {
- return delegate.isEnabledFor(Level.ERROR);
- }
-}
diff --git a/client/src/main/java/com/alibaba/nacos/client/logger/log4j/Log4jLoggerFactory.java b/client/src/main/java/com/alibaba/nacos/client/logger/log4j/Log4jLoggerFactory.java
deleted file mode 100644
index 86ca0aa9f48..00000000000
--- a/client/src/main/java/com/alibaba/nacos/client/logger/log4j/Log4jLoggerFactory.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 1999-2018 Alibaba Group Holding Ltd.
- *
- * 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.
- */
-package com.alibaba.nacos.client.logger.log4j;
-
-import org.apache.log4j.LogManager;
-
-import com.alibaba.nacos.client.logger.Logger;
-import com.alibaba.nacos.client.logger.nop.NopLogger;
-import com.alibaba.nacos.client.logger.support.ILoggerFactory;
-import com.alibaba.nacos.client.logger.support.LogLog;
-
-/**
- * Log4jLogger Factory
- * @author Nacos
- *
- */
-public class Log4jLoggerFactory implements ILoggerFactory {
-
- public Log4jLoggerFactory() throws ClassNotFoundException {
- Class.forName("org.apache.log4j.Level");
- }
-
- public Logger getLogger(Class> clazz) {
- try {
- return new Log4jLogger(LogManager.getLogger(clazz));
- } catch (Throwable t) {
- LogLog.error("Failed to get Log4jLogger", t);
- return new NopLogger();
- }
- }
-
- public Logger getLogger(String name) {
- try {
- return new Log4jLogger(LogManager.getLogger(name));
- } catch (Throwable t) {
- LogLog.error("Failed to get Log4jLogger", t);
- return new NopLogger();
- }
- }
-}
diff --git a/client/src/main/java/com/alibaba/nacos/client/logger/option/AbstractActiveOption.java b/client/src/main/java/com/alibaba/nacos/client/logger/option/AbstractActiveOption.java
index 209054e6816..7debb078d51 100644
--- a/client/src/main/java/com/alibaba/nacos/client/logger/option/AbstractActiveOption.java
+++ b/client/src/main/java/com/alibaba/nacos/client/logger/option/AbstractActiveOption.java
@@ -15,8 +15,6 @@
*/
package com.alibaba.nacos.client.logger.option;
-import org.apache.log4j.AsyncAppender;
-
import com.alibaba.nacos.client.logger.Level;
import com.alibaba.nacos.client.logger.support.LogLog;
diff --git a/client/src/main/java/com/alibaba/nacos/client/logger/option/Log4jActivateOption.java b/client/src/main/java/com/alibaba/nacos/client/logger/option/Log4jActivateOption.java
deleted file mode 100644
index ca3e3a6f9a9..00000000000
--- a/client/src/main/java/com/alibaba/nacos/client/logger/option/Log4jActivateOption.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright 1999-2018 Alibaba Group Holding Ltd.
- *
- * 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.
- */
-package com.alibaba.nacos.client.logger.option;
-
-import org.apache.log4j.*;
-
-import com.alibaba.nacos.client.logger.Logger;
-import com.alibaba.nacos.client.logger.support.LoggerHelper;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * ActivateOption的Log4j实现
- *
- * @author zhuyong 2014年3月20日 上午10:24:36
- */
-public class Log4jActivateOption extends AbstractActiveOption {
-
- protected org.apache.log4j.Logger logger;
-
- public Log4jActivateOption(org.apache.log4j.Logger logger) {
- this.logger = logger;
- }
-
- @Override
- public void activateConsoleAppender(String target, String encoding) {
- org.apache.log4j.ConsoleAppender appender = new org.apache.log4j.ConsoleAppender();
- appender.setLayout(new PatternLayout(LoggerHelper.getPattern()));
- appender.setTarget(target);
- appender.setEncoding(encoding);
- appender.activateOptions();
-
- logger.removeAllAppenders();
- logger.addAppender(appender);
- }
-
- @Override
- public void activateAppender(String productName, String file, String encoding) {
- org.apache.log4j.Appender appender = getLog4jDailyRollingFileAppender(productName, file, encoding);
- logger.removeAllAppenders();
- logger.addAppender(appender);
-
- setProductName(productName);
- }
-
- @Override
- public void activateAsyncAppender(String productName, String file, String encoding) {
- activateAsyncAppender(productName, file, encoding, Integer.MIN_VALUE, Integer.MIN_VALUE);
- }
-
- @Override
- public void activateAsyncAppender(String productName, String file, String encoding, int queueSize,
- int discardingThreshold) {
- activateAppender(productName, file, encoding);
- activateAsync(queueSize, discardingThreshold);
- }
-
- @Override
- public void activateAppenderWithTimeAndSizeRolling(String productName, String file, String encoding, String size) {
- activateAppender(productName, file, encoding);
- }
-
- @Override
- public void setLevel(com.alibaba.nacos.client.logger.Level level) {
- this.level = level;
- logger.setLevel(org.apache.log4j.Level.toLevel(level.getName()));
- }
-
- @Override
- public void setAdditivity(boolean additivity) {
- logger.setAdditivity(additivity);
- }
-
- protected org.apache.log4j.Appender getLog4jDailyRollingFileAppender(String productName, String file,
- String encoding) {
- DailyRollingFileAppender appender = new DailyRollingFileAppender();
- appender.setName(productName + "." + file.replace(File.separatorChar, '.') + ".Appender");
- appender.setLayout(new PatternLayout(LoggerHelper.getPattern(productName)));
- appender.setAppend(true);
- appender.setFile(LoggerHelper.getLogFileP(productName, file));
- appender.setEncoding(encoding);
- appender.activateOptions();
-
- return appender;
- }
-
- @Override
- public void activateAppender(Logger logger) {
- if (!(logger.getDelegate() instanceof org.apache.log4j.Logger)) {
- throw new IllegalArgumentException(
- "logger must be org.apache.log4j.Logger, but it's " + logger.getDelegate().getClass());
- }
- activateAppender((org.apache.log4j.Logger) logger.getDelegate());
-
- setProductName(logger.getProductName());
- }
-
- protected void activateAppender(org.apache.log4j.Logger logger) {
- this.logger.removeAllAppenders();
-
- Enumeration> enums = logger.getAllAppenders();
- while (enums != null && enums.hasMoreElements()) {
- this.logger.addAppender((Appender) enums.nextElement());
- }
- }
-
- @Override
- public void activateAppenderWithTimeAndSizeRolling(String productName, String file, String encoding, String size,
- String datePattern) {
- Appender appender = getLog4jRollingFileAppender(productName, file, encoding, size, datePattern, -1);
-
- logger.removeAllAppenders();
- logger.addAppender(appender);
-
- setProductName(productName);
- }
-
- @Override
- public void activateAppenderWithTimeAndSizeRolling(String productName, String file, String encoding, String size,
- String datePattern, int maxBackupIndex) {
- Appender appender = getLog4jRollingFileAppender(productName, file, encoding, size, datePattern, maxBackupIndex);
- logger.removeAllAppenders();
- logger.addAppender(appender);
-
- setProductName(productName);
- }
-
- protected org.apache.log4j.Appender getLog4jRollingFileAppender(String productName, String file, String encoding,
- String size, String datePattern,
- int maxBackupIndex) {
- RollingFileAppender appender = new RollingFileAppender();
- appender.setName(productName + "." + file.replace(File.separatorChar, '.') + ".Appender");
- appender.setLayout(new PatternLayout(LoggerHelper.getPattern(productName)));
- appender.setAppend(true);
- appender.setFile(LoggerHelper.getLogFileP(productName, file));
- appender.setEncoding(encoding);
- appender.setMaxFileSize(size);
- if (maxBackupIndex >= 0) {
- // 等于0表示直接truck
- appender.setMaxBackupIndex(maxBackupIndex);
- }
- appender.activateOptions();
-
- return appender;
- }
-
- @Override
- public void activateAppenderWithSizeRolling(String productName, String file, String encoding, String size,
- int maxBackupIndex) {
- Appender appender = getLog4jRollingFileAppender(productName, file, encoding, size, null, maxBackupIndex);
- logger.removeAllAppenders();
- logger.addAppender(appender);
-
- setProductName(productName);
- }
-
- @Override
- public void activateAsync(int queueSize, int discardingThreshold) {
- // discardingThreshold is unused for log4j
- List
+