Commits

Anonymous committed 2f812d2

XW-149: Checking log level before doing work in TimerInterceptor and LoggingInterceptor

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@169e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (2)

src/java/com/opensymphony/xwork/interceptor/LoggingInterceptor.java

     }
 
     private void logMessage(ActionInvocation invocation, String baseMessage) {
-        StringBuffer message = new StringBuffer(baseMessage);
-        String namespace = invocation.getProxy().getNamespace();
+        if (log.isInfoEnabled()) {
+            StringBuffer message = new StringBuffer(baseMessage);
+            String namespace = invocation.getProxy().getNamespace();
 
-        if ((namespace != null) && (namespace.trim().length() > 0)) {
-            message.append(namespace).append("/");
-        }
+            if ((namespace != null) && (namespace.trim().length() > 0)) {
+                message.append(namespace).append("/");
+            }
 
-        message.append(invocation.getProxy().getActionName());
-        log.info(message.toString());
+            message.append(invocation.getProxy().getActionName());
+            log.info(message.toString());
+        }
     }
 }

src/java/com/opensymphony/xwork/interceptor/TimerInterceptor.java

     * request by the DefaultActionInvocation or to short-circuit the processing and just return a String return code.
     */
     public String intercept(ActionInvocation invocation) throws Exception {
-        long startTime = System.currentTimeMillis();
-        String result = invocation.invoke();
-        long executionTime = System.currentTimeMillis() - startTime;
-        String namespace = invocation.getProxy().getNamespace();
-        StringBuffer message = new StringBuffer("Processed action ");
-        if ((namespace != null) && (namespace.trim().length() > 0)) {
-            message.append(namespace).append("/");
-        }
-        message.append(invocation.getProxy().getActionName());
-        message.append(" in ").append(executionTime).append("ms.");
-        log.info(message.toString());
+        if (log.isInfoEnabled()) {
+            long startTime = System.currentTimeMillis();
+            String result = invocation.invoke();
+            long executionTime = System.currentTimeMillis() - startTime;
+            String namespace = invocation.getProxy().getNamespace();
+            StringBuffer message = new StringBuffer("Processed action ");
+
+            if ((namespace != null) && (namespace.trim().length() > 0)) {
+                message.append(namespace).append("/");
+            }
 
-        return result;
+            message.append(invocation.getProxy().getActionName());
+            message.append(" in ").append(executionTime).append("ms.");
+            log.info(message.toString());
+
+            return result;
+        } else {
+            return invocation.invoke();
+        }
     }
 }