drop deprecated logging layer

issue:
* WW-4763
This commit is contained in:
Stefaan Dutry
2018-05-19 21:18:46 +02:00
parent 1698d2da76
commit 03ade0597d
20 changed files with 0 additions and 1173 deletions
@@ -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();
}
@@ -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<LoggerClass> loggers = new LinkedList<LoggerClass>(){
{
add(new LoggerClass<CommonsLoggerFactory>("org.apache.commons.logging.LogFactory", CommonsLoggerFactory.class));
add(new LoggerClass<Slf4jLoggerFactory>("org.slf4j.LoggerFactory", Slf4jLoggerFactory.class));
add(new LoggerClass<Log4j2LoggerFactory>("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<T extends LoggerFactory> {
private final String loggerClazzName;
private final Class<T> loggerImplClazz;
public LoggerClass(String loggerClazzName, Class<T> 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);
}
}
}
}
@@ -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:
*
* <pre>
* format("foo #0 #1", "bob", "joe");
* </pre>
*
* will return:
* <pre>
* foo bob joe
* </pre>
*
* @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<String> strArgs = new LinkedList<String>();
for (Object arg : args) {
strArgs.add(arg != null ? arg.toString() : "(null)");
}
return format(msg, strArgs.toArray(new String[strArgs.size()]));
}
}
@@ -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();
}
}
@@ -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));
}
}
@@ -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);
}
}
@@ -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));
}
}
@@ -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();
}
}
@@ -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:
* <pre>
* -Dxwork.loggerFactory=com.opensymphony.xwork2.util.logging.log4j2.Log4j2LoggerFactory
* </pre>
*
* @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));
}
}
@@ -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();
}
}
@@ -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:
* <pre>
* -Dxwork.loggerFactory=com.opensymphony.xwork2.util.logging.slf4j.Slf4jLoggerFactory
* </pre>
*
* @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));
}
}
@@ -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
*
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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(""));
}
}
@@ -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;
@@ -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<T> 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
*/
@@ -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
*/