From 03ade0597d5f5ea24f80d03db92db8fd204d2082 Mon Sep 17 00:00:00 2001 From: Stefaan Dutry Date: Sat, 19 May 2018 21:18:46 +0200 Subject: [PATCH] drop deprecated logging layer issue: * WW-4763 --- .../xwork2/util/logging/Logger.java | 73 --------- .../xwork2/util/logging/LoggerFactory.java | 142 ------------------ .../xwork2/util/logging/LoggerUtils.java | 89 ----------- .../util/logging/commons/CommonsLogger.java | 130 ---------------- .../logging/commons/CommonsLoggerFactory.java | 43 ------ .../xwork2/util/logging/jdk/JdkLogger.java | 128 ---------------- .../util/logging/jdk/JdkLoggerFactory.java | 41 ----- .../util/logging/log4j2/Log4j2Logger.java | 127 ---------------- .../logging/log4j2/Log4j2LoggerFactory.java | 47 ------ .../util/logging/slf4j/Slf4jLogger.java | 128 ---------------- .../logging/slf4j/Slf4jLoggerFactory.java | 47 ------ .../struts2/dispatcher/InitOperations.java | 28 ---- .../filter/StrutsPrepareAndExecuteFilter.java | 1 - .../filter/StrutsPrepareFilter.java | 1 - .../dispatcher/listener/StrutsListener.java | 1 - .../dispatcher/servlet/StrutsServlet.java | 1 - .../xwork2/util/logging/LoggerUtilsTest.java | 42 ------ .../struts2/StrutsInternalTestCase.java | 33 ---- .../apache/struts2/StrutsJUnit4TestCase.java | 32 ---- .../org/apache/struts2/StrutsTestCase.java | 39 ----- 20 files changed, 1173 deletions(-) delete mode 100644 core/src/main/java/com/opensymphony/xwork2/util/logging/Logger.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/util/logging/LoggerFactory.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/util/logging/LoggerUtils.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/util/logging/commons/CommonsLogger.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/util/logging/commons/CommonsLoggerFactory.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/util/logging/jdk/JdkLogger.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/util/logging/jdk/JdkLoggerFactory.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/util/logging/log4j2/Log4j2Logger.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/util/logging/log4j2/Log4j2LoggerFactory.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/util/logging/slf4j/Slf4jLogger.java delete mode 100644 core/src/main/java/com/opensymphony/xwork2/util/logging/slf4j/Slf4jLoggerFactory.java delete mode 100644 core/src/test/java/com/opensymphony/xwork2/util/logging/LoggerUtilsTest.java diff --git a/core/src/main/java/com/opensymphony/xwork2/util/logging/Logger.java b/core/src/main/java/com/opensymphony/xwork2/util/logging/Logger.java deleted file mode 100644 index 8412f9d03..000000000 --- a/core/src/main/java/com/opensymphony/xwork2/util/logging/Logger.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.opensymphony.xwork2.util.logging; - -/** - * Main logger interface for logging things - * - * @deprecated since 2.5 - */ -@Deprecated -public interface Logger { - - void trace(String msg, String... args); - - void trace(String msg, Object... args); - - void trace(String msg, Throwable ex, String... args); - - boolean isTraceEnabled(); - - void debug(String msg, String... args); - - void debug(String msg, Object... args); - - void debug(String msg, Throwable ex, String... args); - - boolean isDebugEnabled(); - - void info(String msg, String... args); - - void info(String msg, Throwable ex, String... args); - - boolean isInfoEnabled(); - - void warn(String msg, String... args); - - void warn(String msg, Object... args); - - void warn(String msg, Throwable ex, String... args); - - boolean isWarnEnabled(); - - void error(String msg, String... args); - - void error(String msg, Object... args); - - void error(String msg, Throwable ex, String... args); - - boolean isErrorEnabled(); - - void fatal(String msg, String... args); - - void fatal(String msg, Throwable ex, String... args); - - boolean isFatalEnabled(); - -} diff --git a/core/src/main/java/com/opensymphony/xwork2/util/logging/LoggerFactory.java b/core/src/main/java/com/opensymphony/xwork2/util/logging/LoggerFactory.java deleted file mode 100644 index 52c7ec777..000000000 --- a/core/src/main/java/com/opensymphony/xwork2/util/logging/LoggerFactory.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.opensymphony.xwork2.util.logging; - -import com.opensymphony.xwork2.XWorkConstants; -import com.opensymphony.xwork2.XWorkException; -import com.opensymphony.xwork2.util.logging.commons.CommonsLoggerFactory; -import com.opensymphony.xwork2.util.logging.jdk.JdkLoggerFactory; -import com.opensymphony.xwork2.util.logging.log4j2.Log4j2LoggerFactory; -import com.opensymphony.xwork2.util.logging.slf4j.Slf4jLoggerFactory; - -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -/** - * Creates loggers. Static accessor will lazily try to decide on the best factory if none specified. - * - * @deprecated since 2.5 - */ -@Deprecated -public abstract class LoggerFactory { - - private static final ReadWriteLock lock = new ReentrantReadWriteLock(); - private static LoggerFactory factory; - - private static final List loggers = new LinkedList(){ - { - add(new LoggerClass("org.apache.commons.logging.LogFactory", CommonsLoggerFactory.class)); - add(new LoggerClass("org.slf4j.LoggerFactory", Slf4jLoggerFactory.class)); - add(new LoggerClass("org.apache.logging.log4j.LogManager", Log4j2LoggerFactory.class)); - } - }; - - public static void setLoggerFactory(LoggerFactory factory) { - lock.writeLock().lock(); - try { - LoggerFactory.factory = factory; - } finally { - lock.writeLock().unlock(); - } - } - - public static Logger getLogger(Class cls) { - return getLoggerFactory().getLoggerImpl(cls); - } - - public static Logger getLogger(String name) { - return getLoggerFactory().getLoggerImpl(name); - } - - protected static LoggerFactory getLoggerFactory() { - lock.readLock().lock(); - try { - if (factory != null) { - return factory; - } - } finally { - lock.readLock().unlock(); - } - lock.writeLock().lock(); - try { - if (factory == null) { - createLoggerFactory(); - } - return factory; - } finally { - lock.writeLock().unlock(); - } - } - - private static void createLoggerFactory() { - String userLoggerFactory = System.getProperty(XWorkConstants.XWORK_LOGGER_FACTORY); - if (userLoggerFactory != null) { - try { - Class clazz = Class.forName(userLoggerFactory); - factory = (LoggerFactory) clazz.newInstance(); - } catch (Exception e) { - throw new XWorkException("System property [" + XWorkConstants.XWORK_LOGGER_FACTORY + - "] was defined as [" + userLoggerFactory + "] but there is a problem to use that LoggerFactory!", e); - } - } else { - factory = new JdkLoggerFactory(); - for (LoggerClass logger : loggers) { - if (logger.isSupported()) { - factory = logger.createInstance(); - break; - } - } - } - } - - protected abstract Logger getLoggerImpl(Class cls); - - protected abstract Logger getLoggerImpl(String name); - - private static class LoggerClass { - - private final String loggerClazzName; - private final Class loggerImplClazz; - - public LoggerClass(String loggerClazzName, Class loggerImplClazz) { - this.loggerClazzName = loggerClazzName; - this.loggerImplClazz = loggerImplClazz; - } - - public boolean isSupported() { - try { - Class.forName(loggerClazzName); - return true; - } catch (ClassNotFoundException ignore) { - return false; - } - } - - public LoggerFactory createInstance() { - try { - return loggerImplClazz.newInstance(); - } catch (Exception e) { - throw new XWorkException(e); - } - } - } - -} diff --git a/core/src/main/java/com/opensymphony/xwork2/util/logging/LoggerUtils.java b/core/src/main/java/com/opensymphony/xwork2/util/logging/LoggerUtils.java deleted file mode 100644 index 30309fc5b..000000000 --- a/core/src/main/java/com/opensymphony/xwork2/util/logging/LoggerUtils.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.opensymphony.xwork2.util.logging; - -import java.util.LinkedList; -import java.util.List; - -/** - * Logging utility methods - * - * @deprecated since 2.5 - */ -@Deprecated -public class LoggerUtils { - - /** - * Formats messages using parameters. For example, the call: - * - *
-     * format("foo #0 #1", "bob", "joe");
-     * 
- * - * will return: - *
-     * foo bob joe
-     * 
- * - * @param msg The message - * @param args A list of arguments. A maximum of 10 are supported. - * @return The formatted string - */ - public static String format(String msg, String... args) { - if (msg != null && msg.length() > 0 && msg.indexOf('#') > -1) { - StringBuilder sb = new StringBuilder(); - boolean isArg = false; - for (int x = 0; x < msg.length(); x++) { - char c = msg.charAt(x); - if (isArg) { - isArg = false; - if (Character.isDigit(c)) { - int val = Character.getNumericValue(c); - if (val >= 0 && val < args.length) { - sb.append(args[val]); - continue; - } - } - sb.append('#'); - } - if (c == '#') { - isArg = true; - continue; - } - sb.append(c); - } - - if (isArg) { - sb.append('#'); - } - return sb.toString(); - } - return msg; - - } - - public static String format(String msg, Object[] args) { - List strArgs = new LinkedList(); - for (Object arg : args) { - strArgs.add(arg != null ? arg.toString() : "(null)"); - } - return format(msg, strArgs.toArray(new String[strArgs.size()])); - } - -} diff --git a/core/src/main/java/com/opensymphony/xwork2/util/logging/commons/CommonsLogger.java b/core/src/main/java/com/opensymphony/xwork2/util/logging/commons/CommonsLogger.java deleted file mode 100644 index 059e6ef06..000000000 --- a/core/src/main/java/com/opensymphony/xwork2/util/logging/commons/CommonsLogger.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.opensymphony.xwork2.util.logging.commons; - -import com.opensymphony.xwork2.util.logging.Logger; -import com.opensymphony.xwork2.util.logging.LoggerUtils; -import org.apache.commons.logging.Log; - -/** - * Simple logger that delegates to commons logging - * - * @deprecated since 2.5 - */ -@Deprecated -public class CommonsLogger implements Logger { - - private Log log; - - public CommonsLogger(Log log) { - this.log = log; - } - - public void error(String msg, String... args) { - log.error(LoggerUtils.format(msg, args)); - } - - public void error(String msg, Object... args) { - log.error(LoggerUtils.format(msg, args)); - } - - public void error(String msg, Throwable ex, String... args) { - log.error(LoggerUtils.format(msg, args), ex); - } - - public void info(String msg, String... args) { - log.info(LoggerUtils.format(msg, args)); - } - - public void info(String msg, Throwable ex, String... args) { - log.info(LoggerUtils.format(msg, args), ex); - } - - - - public boolean isInfoEnabled() { - return log.isInfoEnabled(); - } - - public void warn(String msg, String... args) { - log.warn(LoggerUtils.format(msg, args)); - } - - public void warn(String msg, Object... args) { - log.warn(LoggerUtils.format(msg, args)); - } - - public void warn(String msg, Throwable ex, String... args) { - log.warn(LoggerUtils.format(msg, args), ex); - } - - public boolean isDebugEnabled() { - return log.isDebugEnabled(); - } - - public void debug(String msg, String... args) { - log.debug(LoggerUtils.format(msg, args)); - } - - public void debug(String msg, Object... args) { - log.debug(LoggerUtils.format(msg, args)); - } - - public void debug(String msg, Throwable ex, String... args) { - log.debug(LoggerUtils.format(msg, args), ex); - } - - public boolean isTraceEnabled() { - return log.isTraceEnabled(); - } - - public void trace(String msg, String... args) { - log.trace(LoggerUtils.format(msg, args)); - } - - public void trace(String msg, Object... args) { - log.trace(LoggerUtils.format(msg, args)); - } - - public void trace(String msg, Throwable ex, String... args) { - log.trace(LoggerUtils.format(msg, args), ex); - } - - - public void fatal(String msg, String... args) { - log.fatal(LoggerUtils.format(msg, args)); - } - - public void fatal(String msg, Throwable ex, String... args) { - log.fatal(LoggerUtils.format(msg, args), ex); - } - - public boolean isErrorEnabled() { - return log.isErrorEnabled(); - } - - public boolean isFatalEnabled() { - return log.isFatalEnabled(); - } - - public boolean isWarnEnabled() { - return log.isWarnEnabled(); - } - -} diff --git a/core/src/main/java/com/opensymphony/xwork2/util/logging/commons/CommonsLoggerFactory.java b/core/src/main/java/com/opensymphony/xwork2/util/logging/commons/CommonsLoggerFactory.java deleted file mode 100644 index cd8f9f00b..000000000 --- a/core/src/main/java/com/opensymphony/xwork2/util/logging/commons/CommonsLoggerFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.opensymphony.xwork2.util.logging.commons; - -import com.opensymphony.xwork2.util.logging.Logger; -import com.opensymphony.xwork2.util.logging.LoggerFactory; -import org.apache.commons.logging.LogFactory; - -/** - * Creates commons-logging-backed loggers - * - * @deprecated since 2.5 - */ -@Deprecated -public class CommonsLoggerFactory extends LoggerFactory { - - @Override - protected Logger getLoggerImpl(Class cls) { - return new CommonsLogger(LogFactory.getLog(cls)); - } - - @Override - protected Logger getLoggerImpl(String name) { - return new CommonsLogger(LogFactory.getLog(name)); - } - -} diff --git a/core/src/main/java/com/opensymphony/xwork2/util/logging/jdk/JdkLogger.java b/core/src/main/java/com/opensymphony/xwork2/util/logging/jdk/JdkLogger.java deleted file mode 100644 index 5d03ef4f1..000000000 --- a/core/src/main/java/com/opensymphony/xwork2/util/logging/jdk/JdkLogger.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.opensymphony.xwork2.util.logging.jdk; - -import com.opensymphony.xwork2.util.logging.Logger; -import com.opensymphony.xwork2.util.logging.LoggerUtils; - -import java.util.logging.Level; - -/** - * Delegates to jdk logger. Maps fatal to Level.SEVERE along with error. - * - * @deprecated since 2.5 - */ -@Deprecated -public class JdkLogger implements Logger { - - private java.util.logging.Logger log; - - public JdkLogger(java.util.logging.Logger log) { - this.log = log; - } - - public void error(String msg, String... args) { - log.log(Level.SEVERE, LoggerUtils.format(msg, args)); - } - - public void error(String msg, Object... args) { - log.log(Level.SEVERE, LoggerUtils.format(msg, args)); - } - - public void error(String msg, Throwable ex, String... args) { - log.log(Level.SEVERE, LoggerUtils.format(msg, args), ex); - } - - public void fatal(String msg, String... args) { - log.log(Level.SEVERE, LoggerUtils.format(msg, args)); - } - - public void fatal(String msg, Throwable ex, String... args) { - log.log(Level.SEVERE, LoggerUtils.format(msg, args), ex); - } - - public void info(String msg, String... args) { - log.log(Level.INFO, LoggerUtils.format(msg, args)); - } - - public void info(String msg, Throwable ex, String... args) { - log.log(Level.INFO, LoggerUtils.format(msg, args), ex); - } - - public boolean isInfoEnabled() { - return log.isLoggable(Level.INFO); - } - - public void warn(String msg, String... args) { - log.log(Level.WARNING, LoggerUtils.format(msg, args)); - } - - public void warn(String msg, Object... args) { - log.log(Level.WARNING, LoggerUtils.format(msg, args)); - } - - public void warn(String msg, Throwable ex, String... args) { - log.log(Level.WARNING, LoggerUtils.format(msg, args), ex); - } - - public boolean isDebugEnabled() { - return log.isLoggable(Level.FINE); - } - - public void debug(String msg, String... args) { - log.log(Level.FINE, LoggerUtils.format(msg, args)); - } - - public void debug(String msg, Object... args) { - log.log(Level.FINE, LoggerUtils.format(msg, args)); - } - - public void debug(String msg, Throwable ex, String... args) { - log.log(Level.FINE, LoggerUtils.format(msg, args), ex); - } - - public boolean isTraceEnabled() { - return log.isLoggable(Level.FINEST); - } - - public void trace(String msg, String... args) { - log.log(Level.FINEST, LoggerUtils.format(msg, args)); - } - - public void trace(String msg, Object... args) { - log.log(Level.FINEST, LoggerUtils.format(msg, args)); - } - - public void trace(String msg, Throwable ex, String... args) { - log.log(Level.FINEST, LoggerUtils.format(msg, args), ex); - } - - public boolean isErrorEnabled() { - return log.isLoggable(Level.SEVERE); - } - - public boolean isFatalEnabled() { - return log.isLoggable(Level.SEVERE); - } - - public boolean isWarnEnabled() { - return log.isLoggable(Level.WARNING); - } - -} diff --git a/core/src/main/java/com/opensymphony/xwork2/util/logging/jdk/JdkLoggerFactory.java b/core/src/main/java/com/opensymphony/xwork2/util/logging/jdk/JdkLoggerFactory.java deleted file mode 100644 index d32f2c8a1..000000000 --- a/core/src/main/java/com/opensymphony/xwork2/util/logging/jdk/JdkLoggerFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.opensymphony.xwork2.util.logging.jdk; - -import com.opensymphony.xwork2.util.logging.Logger; -import com.opensymphony.xwork2.util.logging.LoggerFactory; - -/** - * Creates jdk loggers - * - * @deprecated since 2.5 - */ -@Deprecated -public class JdkLoggerFactory extends LoggerFactory { - - @Override - protected Logger getLoggerImpl(Class cls) { - return new JdkLogger(java.util.logging.Logger.getLogger(cls.getName())); - } - - @Override - protected Logger getLoggerImpl(String name) { - return new JdkLogger(java.util.logging.Logger.getLogger(name)); - } -} diff --git a/core/src/main/java/com/opensymphony/xwork2/util/logging/log4j2/Log4j2Logger.java b/core/src/main/java/com/opensymphony/xwork2/util/logging/log4j2/Log4j2Logger.java deleted file mode 100644 index 8fe2010e0..000000000 --- a/core/src/main/java/com/opensymphony/xwork2/util/logging/log4j2/Log4j2Logger.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.opensymphony.xwork2.util.logging.log4j2; - -import com.opensymphony.xwork2.util.logging.Logger; -import com.opensymphony.xwork2.util.logging.LoggerUtils; - -/** - * Simple logger that delegates to log4j2 logging - * - * @deprecated since 2.5 - */ -@Deprecated -public class Log4j2Logger implements Logger { - - private org.apache.logging.log4j.Logger log; - - public Log4j2Logger(org.apache.logging.log4j.Logger log) { - this.log = log; - } - - public void error(String msg, String... args) { - log.error(LoggerUtils.format(msg, args)); - } - - public void error(String msg, Object... args) { - log.error(LoggerUtils.format(msg, args)); - } - - public void error(String msg, Throwable ex, String... args) { - log.error(LoggerUtils.format(msg, args), ex); - } - - public void info(String msg, String... args) { - log.info(LoggerUtils.format(msg, args)); - } - - public void info(String msg, Throwable ex, String... args) { - log.info(LoggerUtils.format(msg, args), ex); - } - - public boolean isInfoEnabled() { - return log.isInfoEnabled(); - } - - public void warn(String msg, String... args) { - log.warn(LoggerUtils.format(msg, args)); - } - - public void warn(String msg, Object... args) { - log.warn(LoggerUtils.format(msg, args)); - } - - public void warn(String msg, Throwable ex, String... args) { - log.warn(LoggerUtils.format(msg, args), ex); - } - - public boolean isDebugEnabled() { - return log.isDebugEnabled(); - } - - public void debug(String msg, String... args) { - log.debug(LoggerUtils.format(msg, args)); - } - - public void debug(String msg, Object... args) { - log.debug(LoggerUtils.format(msg, args)); - } - - public void debug(String msg, Throwable ex, String... args) { - log.debug(LoggerUtils.format(msg, args), ex); - } - - public boolean isTraceEnabled() { - return log.isTraceEnabled(); - } - - public void trace(String msg, String... args) { - log.trace(LoggerUtils.format(msg, args)); - } - - public void trace(String msg, Object... args) { - log.trace(LoggerUtils.format(msg, args)); - } - - public void trace(String msg, Throwable ex, String... args) { - log.trace(LoggerUtils.format(msg, args), ex); - } - - - public void fatal(String msg, String... args) { - log.fatal(LoggerUtils.format(msg, args)); - } - - public void fatal(String msg, Throwable ex, String... args) { - log.fatal(LoggerUtils.format(msg, args), ex); - } - - public boolean isErrorEnabled() { - return log.isErrorEnabled(); - } - - public boolean isFatalEnabled() { - return log.isFatalEnabled(); - } - - public boolean isWarnEnabled() { - return log.isWarnEnabled(); - } - -} diff --git a/core/src/main/java/com/opensymphony/xwork2/util/logging/log4j2/Log4j2LoggerFactory.java b/core/src/main/java/com/opensymphony/xwork2/util/logging/log4j2/Log4j2LoggerFactory.java deleted file mode 100644 index 7b9eed1fc..000000000 --- a/core/src/main/java/com/opensymphony/xwork2/util/logging/log4j2/Log4j2LoggerFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.opensymphony.xwork2.util.logging.log4j2; - -import com.opensymphony.xwork2.util.logging.Logger; -import com.opensymphony.xwork2.util.logging.LoggerFactory; - -/** - * Creates log4j2-logging-backed loggers - * - * You can use the same to explicit tell the framework which implementation to use and don't depend on class discovery: - *
- *   -Dxwork.loggerFactory=com.opensymphony.xwork2.util.logging.log4j2.Log4j2LoggerFactory
- * 
- * - * @deprecated since 2.5 - */ -@Deprecated -public class Log4j2LoggerFactory extends LoggerFactory { - - @Override - protected Logger getLoggerImpl(Class cls) { - return new Log4j2Logger(org.apache.logging.log4j.LogManager.getLogger(cls)); - } - - @Override - protected Logger getLoggerImpl(String name) { - return new Log4j2Logger(org.apache.logging.log4j.LogManager.getLogger(name)); - } - -} diff --git a/core/src/main/java/com/opensymphony/xwork2/util/logging/slf4j/Slf4jLogger.java b/core/src/main/java/com/opensymphony/xwork2/util/logging/slf4j/Slf4jLogger.java deleted file mode 100644 index 49124d1a1..000000000 --- a/core/src/main/java/com/opensymphony/xwork2/util/logging/slf4j/Slf4jLogger.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.opensymphony.xwork2.util.logging.slf4j; - -import com.opensymphony.xwork2.util.logging.Logger; -import com.opensymphony.xwork2.util.logging.LoggerUtils; - -/** - * Simple logger that delegates to slf4j logging - * - * @deprecated since 2.5 - */ -@Deprecated -public class Slf4jLogger implements Logger { - - private org.slf4j.Logger log; - - public Slf4jLogger(org.slf4j.Logger log) { - this.log = log; - } - - public void error(String msg, String... args) { - log.error(LoggerUtils.format(msg, args)); - } - - public void error(String msg, Object... args) { - log.error(LoggerUtils.format(msg, args)); - } - - public void error(String msg, Throwable ex, String... args) { - log.error(LoggerUtils.format(msg, args), ex); - } - - public void info(String msg, String... args) { - log.info(LoggerUtils.format(msg, args)); - } - - public void info(String msg, Throwable ex, String... args) { - log.info(LoggerUtils.format(msg, args), ex); - } - - public boolean isInfoEnabled() { - return log.isInfoEnabled(); - } - - public void warn(String msg, String... args) { - log.warn(LoggerUtils.format(msg, args)); - } - - public void warn(String msg, Object... args) { - log.warn(LoggerUtils.format(msg, args)); - } - - public void warn(String msg, Throwable ex, String... args) { - log.warn(LoggerUtils.format(msg, args), ex); - } - - public boolean isDebugEnabled() { - return log.isDebugEnabled(); - } - - public void debug(String msg, String... args) { - log.debug(LoggerUtils.format(msg, args)); - } - - public void debug(String msg, Object... args) { - log.debug(LoggerUtils.format(msg, args)); - } - - public void debug(String msg, Throwable ex, String... args) { - log.debug(LoggerUtils.format(msg, args), ex); - } - - public boolean isTraceEnabled() { - return log.isTraceEnabled(); - } - - public void trace(String msg, String... args) { - log.trace(LoggerUtils.format(msg, args)); - } - - public void trace(String msg, Object... args) { - log.trace(LoggerUtils.format(msg, args)); - } - - public void trace(String msg, Throwable ex, String... args) { - log.trace(LoggerUtils.format(msg, args), ex); - } - - - public void fatal(String msg, String... args) { - log.error(LoggerUtils.format(msg, args)); - } - - public void fatal(String msg, Throwable ex, String... args) { - log.error(LoggerUtils.format(msg, args), ex); - } - - public boolean isErrorEnabled() { - return log.isErrorEnabled(); - } - - /** Fatal is not support by Slf4j */ - public boolean isFatalEnabled() { - return log.isErrorEnabled(); - } - - public boolean isWarnEnabled() { - return log.isWarnEnabled(); - } - -} diff --git a/core/src/main/java/com/opensymphony/xwork2/util/logging/slf4j/Slf4jLoggerFactory.java b/core/src/main/java/com/opensymphony/xwork2/util/logging/slf4j/Slf4jLoggerFactory.java deleted file mode 100644 index ef267429c..000000000 --- a/core/src/main/java/com/opensymphony/xwork2/util/logging/slf4j/Slf4jLoggerFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.opensymphony.xwork2.util.logging.slf4j; - -import com.opensymphony.xwork2.util.logging.Logger; -import com.opensymphony.xwork2.util.logging.LoggerFactory; - -/** - * Creates slf4j-logging-backed loggers - * - * You can use the same to explicit tell the framework which implementation to use and don't depend on class discovery: - *
- *   -Dxwork.loggerFactory=com.opensymphony.xwork2.util.logging.slf4j.Slf4jLoggerFactory
- * 
- * - * @deprecated since 2.5 - */ -@Deprecated -public class Slf4jLoggerFactory extends LoggerFactory { - - @Override - protected Logger getLoggerImpl(Class cls) { - return new Slf4jLogger(org.slf4j.LoggerFactory.getLogger(cls)); - } - - @Override - protected Logger getLoggerImpl(String name) { - return new Slf4jLogger(org.slf4j.LoggerFactory.getLogger(name)); - } - -} diff --git a/core/src/main/java/org/apache/struts2/dispatcher/InitOperations.java b/core/src/main/java/org/apache/struts2/dispatcher/InitOperations.java index c98b61771..55f648177 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/InitOperations.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/InitOperations.java @@ -20,7 +20,6 @@ package org.apache.struts2.dispatcher; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.util.ClassLoaderUtil; -import com.opensymphony.xwork2.util.logging.LoggerFactory; import org.apache.struts2.StrutsConstants; import java.util.*; @@ -34,33 +33,6 @@ public class InitOperations { public InitOperations() { } - /** - * Initializes the internal Struts logging - * - * @param filterConfig host configuration - * @deprecated since 2.5 - */ - @Deprecated - public void initLogging( HostConfig filterConfig ) { - String factoryName = filterConfig.getInitParameter("loggerFactory"); - if (factoryName != null) { - try { - Class cls = ClassLoaderUtil.loadClass(factoryName, this.getClass()); - LoggerFactory fac = (LoggerFactory) cls.newInstance(); - LoggerFactory.setLoggerFactory(fac); - } catch ( InstantiationException e ) { - System.err.println("Unable to instantiate logger factory: " + factoryName + ", using default"); - e.printStackTrace(); - } catch ( IllegalAccessException e ) { - System.err.println("Unable to access logger factory: " + factoryName + ", using default"); - e.printStackTrace(); - } catch ( ClassNotFoundException e ) { - System.err.println("Unable to locate logger factory class: " + factoryName + ", using default"); - e.printStackTrace(); - } - } - } - /** * Creates and initializes the dispatcher * diff --git a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareAndExecuteFilter.java b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareAndExecuteFilter.java index 9f2f2bfd6..73f5860ec 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareAndExecuteFilter.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareAndExecuteFilter.java @@ -57,7 +57,6 @@ public class StrutsPrepareAndExecuteFilter implements StrutsStatics, Filter { Dispatcher dispatcher = null; try { FilterHostConfig config = new FilterHostConfig(filterConfig); - init.initLogging(config); dispatcher = init.initDispatcher(config); init.initStaticContentLoader(config, dispatcher); diff --git a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java index 888ecacfd..0332fa342 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java @@ -50,7 +50,6 @@ public class StrutsPrepareFilter implements StrutsStatics, Filter { Dispatcher dispatcher = null; try { FilterHostConfig config = new FilterHostConfig(filterConfig); - init.initLogging(config); dispatcher = init.initDispatcher(config); prepare = new PrepareOperations(dispatcher); diff --git a/core/src/main/java/org/apache/struts2/dispatcher/listener/StrutsListener.java b/core/src/main/java/org/apache/struts2/dispatcher/listener/StrutsListener.java index ab91debfe..bf8398406 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/listener/StrutsListener.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/listener/StrutsListener.java @@ -40,7 +40,6 @@ public class StrutsListener implements ServletContextListener { Dispatcher dispatcher = null; try { ListenerHostConfig config = new ListenerHostConfig(sce.getServletContext()); - init.initLogging(config); dispatcher = init.initDispatcher(config); init.initStaticContentLoader(config, dispatcher); diff --git a/core/src/main/java/org/apache/struts2/dispatcher/servlet/StrutsServlet.java b/core/src/main/java/org/apache/struts2/dispatcher/servlet/StrutsServlet.java index 1070d4569..02132fc93 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/servlet/StrutsServlet.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/servlet/StrutsServlet.java @@ -49,7 +49,6 @@ public class StrutsServlet extends HttpServlet { Dispatcher dispatcher = null; try { ServletHostConfig config = new ServletHostConfig(filterConfig); - init.initLogging(config); dispatcher = init.initDispatcher(config); init.initStaticContentLoader(config, dispatcher); diff --git a/core/src/test/java/com/opensymphony/xwork2/util/logging/LoggerUtilsTest.java b/core/src/test/java/com/opensymphony/xwork2/util/logging/LoggerUtilsTest.java deleted file mode 100644 index baf1a97a3..000000000 --- a/core/src/test/java/com/opensymphony/xwork2/util/logging/LoggerUtilsTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.opensymphony.xwork2.util.logging; - - -import junit.framework.TestCase; - -public class LoggerUtilsTest extends TestCase { - - public void testFormatMessage() { - assertEquals("foo", LoggerUtils.format("foo")); - assertEquals("foo #", LoggerUtils.format("foo #")); - assertEquals("#foo", LoggerUtils.format("#foo")); - assertEquals("foo #1", LoggerUtils.format("foo #1")); - assertEquals("foo bob", LoggerUtils.format("foo #0", "bob")); - assertEquals("foo bob joe", LoggerUtils.format("foo #0 #1", "bob", "joe")); - assertEquals("foo bob joe #8", LoggerUtils.format("foo #0 #1 #8", "bob", "joe")); - assertEquals("foo (bob/ally)", LoggerUtils.format("foo (#0/#1)", "bob", "ally")); - assertEquals("foo (bobally)", LoggerUtils.format("foo (#0#1)", "bob", "ally")); - - assertEquals(null, LoggerUtils.format(null)); - assertEquals("", LoggerUtils.format("")); - - } - -} diff --git a/core/src/test/java/org/apache/struts2/StrutsInternalTestCase.java b/core/src/test/java/org/apache/struts2/StrutsInternalTestCase.java index f60ae9506..dfc2dc3a4 100644 --- a/core/src/test/java/org/apache/struts2/StrutsInternalTestCase.java +++ b/core/src/test/java/org/apache/struts2/StrutsInternalTestCase.java @@ -19,8 +19,6 @@ package org.apache.struts2; import com.opensymphony.xwork2.XWorkTestCase; -import com.opensymphony.xwork2.util.logging.LoggerFactory; -import com.opensymphony.xwork2.util.logging.jdk.JdkLoggerFactory; import org.apache.struts2.dispatcher.Dispatcher; import org.apache.struts2.util.StrutsTestCaseHelper; import org.apache.struts2.views.jsp.StrutsMockServletContext; @@ -29,43 +27,12 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; -import java.util.logging.*; /** * Base test case for JUnit testing Struts. */ public abstract class StrutsInternalTestCase extends XWorkTestCase { - static { - ConsoleHandler handler = new ConsoleHandler(); - final SimpleDateFormat df = new SimpleDateFormat("mm:ss.SSS"); - Formatter formatter = new Formatter() { - @Override - public String format(LogRecord record) { - StringBuilder sb = new StringBuilder(); - sb.append(record.getLevel()); - sb.append(':'); - for (int x=9-record.getLevel().toString().length(); x>0; x--) { - sb.append(' '); - } - sb.append('['); - sb.append(df.format(new Date(record.getMillis()))); - sb.append("] "); - sb.append(formatMessage(record)); - sb.append('\n'); - return sb.toString(); - } - }; - handler.setFormatter(formatter); - Logger logger = Logger.getLogger(""); - if (logger.getHandlers().length > 0) { - logger.removeHandler(logger.getHandlers()[0]); - } - logger.addHandler(handler); - logger.setLevel(Level.WARNING); - LoggerFactory.setLoggerFactory(new JdkLoggerFactory()); - } - protected StrutsMockServletContext servletContext; protected Dispatcher dispatcher; diff --git a/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java b/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java index 9a917e3cf..153fcf66c 100644 --- a/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java +++ b/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java @@ -26,8 +26,6 @@ import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.interceptor.ValidationAware; import com.opensymphony.xwork2.interceptor.annotations.After; import com.opensymphony.xwork2.interceptor.annotations.Before; -import com.opensymphony.xwork2.util.logging.LoggerFactory; -import com.opensymphony.xwork2.util.logging.jdk.JdkLoggerFactory; import org.apache.commons.lang3.StringUtils; import org.apache.struts2.dispatcher.Dispatcher; import org.apache.struts2.dispatcher.HttpParameters; @@ -51,7 +49,6 @@ import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; -import java.util.logging.*; import static org.junit.Assert.assertNotNull; @@ -67,35 +64,6 @@ public abstract class StrutsJUnit4TestCase extends XWorkJUnit4TestCase { protected DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); - static { - ConsoleHandler handler = new ConsoleHandler(); - final SimpleDateFormat df = new SimpleDateFormat("mm:ss.SSS"); - Formatter formatter = new Formatter() { - @Override - public String format(LogRecord record) { - StringBuilder sb = new StringBuilder(); - sb.append(record.getLevel()); - sb.append(':'); - for (int x = 9 - record.getLevel().toString().length(); x > 0; x--) { - sb.append(' '); - } - sb.append('['); - sb.append(df.format(new Date(record.getMillis()))); - sb.append("] "); - sb.append(formatMessage(record)); - sb.append('\n'); - return sb.toString(); - } - }; - handler.setFormatter(formatter); - Logger logger = Logger.getLogger(""); - if (logger.getHandlers().length > 0) - logger.removeHandler(logger.getHandlers()[0]); - logger.addHandler(handler); - logger.setLevel(Level.WARNING); - LoggerFactory.setLoggerFactory(new JdkLoggerFactory()); - } - /** * gets an object from the stack after an action is executed */ diff --git a/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java b/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java index f28c286f9..c72623c3a 100644 --- a/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java +++ b/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java @@ -23,9 +23,6 @@ import com.opensymphony.xwork2.ActionProxy; import com.opensymphony.xwork2.ActionProxyFactory; import com.opensymphony.xwork2.XWorkTestCase; import com.opensymphony.xwork2.config.Configuration; -import com.opensymphony.xwork2.util.logging.LoggerFactory; -import org.apache.logging.log4j.LogManager; -import com.opensymphony.xwork2.util.logging.jdk.JdkLoggerFactory; import org.apache.struts2.dispatcher.Dispatcher; import org.apache.struts2.dispatcher.HttpParameters; import org.apache.struts2.dispatcher.mapper.ActionMapper; @@ -46,11 +43,6 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; -import java.util.logging.ConsoleHandler; -import java.util.logging.Formatter; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; /** * Base test case for JUnit testing Struts. @@ -65,37 +57,6 @@ public abstract class StrutsTestCase extends XWorkTestCase { protected DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); - static { - ConsoleHandler handler = new ConsoleHandler(); - final SimpleDateFormat df = new SimpleDateFormat("mm:ss.SSS"); - Formatter formatter = new Formatter() { - @Override - public String format(LogRecord record) { - StringBuilder sb = new StringBuilder(); - sb.append(record.getLevel()); - sb.append(':'); - for (int x = 9 - record.getLevel().toString().length(); x > 0; x--) { - sb.append(' '); - } - sb.append('['); - sb.append(df.format(new Date(record.getMillis()))); - sb.append("] "); - sb.append(formatMessage(record)); - sb.append('\n'); - return sb.toString(); - } - }; - handler.setFormatter(formatter); - Logger logger = Logger.getLogger(""); - if (logger.getHandlers().length > 0) - logger.removeHandler(logger.getHandlers()[0]); - logger.addHandler(handler); - logger.setLevel(Level.WARNING); - LoggerFactory.setLoggerFactory(new JdkLoggerFactory()); - } - - private static final com.opensymphony.xwork2.util.logging.Logger LOG = LoggerFactory.getLogger(StrutsTestCase.class); - /** * gets an object from the stack after an action is executed */