WW-4102 Reduces LOG visibility

This commit is contained in:
Lukasz Lenart
2016-12-30 14:11:16 +01:00
parent e38a71365a
commit 3ce21403ee
9 changed files with 26 additions and 31 deletions
@@ -19,21 +19,16 @@ import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.interceptor.ValidationAware;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.Serializable;
import java.util.*;
/**
* Provides a default implementation for the most common actions.
* See the documentation for all the interfaces this class implements for more detailed information.
*/
public class ActionSupport implements Action, Validateable, ValidationAware, TextProvider, LocaleProvider, Serializable {
protected static Logger LOG = LogManager.getLogger(ActionSupport.class);
private final ValidationAwareSupport validationAware = new ValidationAwareSupport();
private transient TextProvider textProvider;
@@ -153,7 +153,7 @@ import java.util.Map;
*/
public class ExceptionMappingInterceptor extends AbstractInterceptor {
protected static final Logger LOG = LogManager.getLogger(ExceptionMappingInterceptor.class);
private static final Logger LOG = LogManager.getLogger(ExceptionMappingInterceptor.class);
protected Logger categoryLogger;
protected boolean logEnabled = false;
@@ -70,7 +70,8 @@ import java.util.Set;
* @see com.opensymphony.xwork2.validator.ValidationInterceptor
*/
public abstract class MethodFilterInterceptor extends AbstractInterceptor {
protected transient Logger log = LogManager.getLogger(getClass());
private static final Logger LOG = LogManager.getLogger(MethodFilterInterceptor.class);
protected Set<String> excludeMethods = Collections.emptySet();
protected Set<String> includeMethods = Collections.emptySet();
@@ -104,7 +105,7 @@ public abstract class MethodFilterInterceptor extends AbstractInterceptor {
// ValidationInterceptor
boolean applyMethod = MethodFilterInterceptorUtil.applyMethod(excludeMethods, includeMethods, method);
if (!applyMethod) {
log.debug("Skipping Interceptor... Method [{}] found in exclude list.", method);
LOG.debug("Skipping Interceptor... Method [{}] found in exclude list.", method);
}
return applyMethod;
}
@@ -93,7 +93,8 @@ import org.apache.logging.log4j.Logger;
* @author Claus Ibsen
*/
public class TimerInterceptor extends AbstractInterceptor {
protected static final Logger LOG = LogManager.getLogger(TimerInterceptor.class);
private static final Logger LOG = LogManager.getLogger(TimerInterceptor.class);
protected Logger categoryLogger;
protected String logCategory;
@@ -129,15 +129,15 @@ import org.apache.logging.log4j.Logger;
*/
public class ValidationInterceptor extends MethodFilterInterceptor {
private static final Logger LOG = LogManager.getLogger(ValidationInterceptor.class);
private final static String VALIDATE_PREFIX = "validate";
private final static String ALT_VALIDATE_PREFIX = "validateDo";
private boolean validateAnnotatedMethodOnly;
private ActionValidatorManager actionValidatorManager;
private static final Logger LOG = LogManager.getLogger(ValidationInterceptor.class);
private final static String VALIDATE_PREFIX = "validate";
private final static String ALT_VALIDATE_PREFIX = "validateDo";
private boolean alwaysInvokeValidate = true;
private boolean programmatic = true;
private boolean declarative = true;
@@ -212,8 +212,8 @@ public class ValidationInterceptor extends MethodFilterInterceptor {
String context = this.getValidationContext(proxy);
String method = proxy.getMethod();
if (log.isDebugEnabled()) {
log.debug("Validating {}/{} with method {}.", invocation.getProxy().getNamespace(), invocation.getProxy().getActionName(), method);
if (LOG.isDebugEnabled()) {
LOG.debug("Validating {}/{} with method {}.", invocation.getProxy().getNamespace(), invocation.getProxy().getActionName(), method);
}
@@ -26,6 +26,8 @@ import com.opensymphony.xwork2.TextProvider;
import com.opensymphony.xwork2.interceptor.ValidationAware;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.util.TokenHelper;
@@ -116,7 +118,7 @@ import javax.servlet.http.HttpSession;
*/
public class TokenInterceptor extends MethodFilterInterceptor {
private static final long serialVersionUID = -6680894220590585506L;
private static final Logger LOG = LogManager.getLogger(TokenInterceptor.class);
public static final String INVALID_TOKEN_CODE = "invalid.token";
@@ -135,7 +137,7 @@ public class TokenInterceptor extends MethodFilterInterceptor {
*/
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
log.debug("Intercepting invocation to check for valid transaction token.");
LOG.debug("Intercepting invocation to check for valid transaction token.");
return handleToken(invocation);
}
@@ -165,7 +167,7 @@ public class TokenInterceptor extends MethodFilterInterceptor {
if (action instanceof ValidationAware) {
((ValidationAware) action).addActionError(errorMessage);
} else {
log.warn(errorMessage);
LOG.warn(errorMessage);
}
return INVALID_TOKEN_CODE;
@@ -55,21 +55,18 @@ public class TimerInterceptorTest extends XWorkTestCase {
public void testDefault() throws Exception {
interceptor.intercept(mai);
assertTrue(interceptor.message.startsWith("Executed action [myApp/myAction!execute] took "));
assertSame(interceptor.logger, TimerInterceptor.LOG);
}
public void testNoNamespace() throws Exception {
ap.setNamespace(null);
interceptor.intercept(mai);
assertTrue(interceptor.message.startsWith("Executed action [myAction!execute] took "));
assertSame(interceptor.logger, TimerInterceptor.LOG);
}
public void testInputMethod() throws Exception {
ap.setMethod("input");
interceptor.intercept(mai);
assertTrue(interceptor.message.startsWith("Executed action [myApp/myAction!input] took "));
assertSame(interceptor.logger, TimerInterceptor.LOG);
}
public void testTraceLevel() throws Exception {
@@ -89,35 +86,30 @@ public class TimerInterceptorTest extends XWorkTestCase {
interceptor.setLogLevel("info");
interceptor.intercept(mai);
assertTrue(interceptor.message.startsWith("Executed action [myApp/myAction!execute] took "));
assertSame(interceptor.logger, TimerInterceptor.LOG);
}
public void testWarnLevel() throws Exception {
interceptor.setLogLevel("warn");
interceptor.intercept(mai);
assertTrue(interceptor.message.startsWith("Executed action [myApp/myAction!execute] took "));
assertSame(interceptor.logger, TimerInterceptor.LOG);
}
public void testErrorLevel() throws Exception {
interceptor.setLogLevel("error");
interceptor.intercept(mai);
assertTrue(interceptor.message.startsWith("Executed action [myApp/myAction!execute] took "));
assertSame(interceptor.logger, TimerInterceptor.LOG);
}
public void testFatalLevel() throws Exception {
interceptor.setLogLevel("fatal");
interceptor.intercept(mai);
assertTrue(interceptor.message.startsWith("Executed action [myApp/myAction!execute] took "));
assertSame(interceptor.logger, TimerInterceptor.LOG);
}
public void testLogCategory() throws Exception {
interceptor.setLogCategory("com.mycompany.myapp.actiontiming");
interceptor.intercept(mai);
assertTrue(interceptor.message.startsWith("Executed action [myApp/myAction!execute] took "));
assertNotSame(interceptor.logger, TimerInterceptor.LOG);
}
public void testLogCategoryLevel() throws Exception {
@@ -125,7 +117,6 @@ public class TimerInterceptorTest extends XWorkTestCase {
interceptor.setLogLevel("error");
interceptor.intercept(mai);
assertTrue(interceptor.message.startsWith("Executed action [myApp/myAction!execute] took "));
assertNotSame(interceptor.logger, TimerInterceptor.LOG);
assertEquals("com.mycompany.myapp.actiontiming", interceptor.getLogCategory());
}
@@ -27,6 +27,8 @@ import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.validator.ActionValidatorManager;
import com.opensymphony.xwork2.validator.Validator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Collections;
import java.util.List;
@@ -37,7 +39,7 @@ import java.util.List;
*/
public class ListValidatorsAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private static final Logger LOG = LogManager.getLogger(ListValidatorsAction.class);
private String clazz;
private String context;
@@ -22,6 +22,8 @@
package org.apache.struts2.config_browser;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.net.URL;
@@ -35,6 +37,8 @@ import java.util.Properties;
*/
public class ShowJarsAction extends ActionNamesAction {
private static final Logger LOG = LogManager.getLogger(ShowJarsAction.class);
public List<Properties> getJarPoms() {
try {
return configHelper.getJarProperties();
@@ -52,8 +56,7 @@ public class ShowJarsAction extends ActionNamesAction {
try {
return ClassLoaderUtil.getResources("struts-plugin.xml", ShowJarsAction.class, false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
LOG.error("Cannot load struts-plugin.xml", e);
}
return null;
}