tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1242371 - in /tomcat/trunk: ./ java/org/apache/juli/logging/ java/org/apache/tomcat/util/http/ java/org/apache/tomcat/util/log/
Date Thu, 09 Feb 2012 16:08:49 GMT
Author: markt
Date: Thu Feb  9 16:08:49 2012
New Revision: 1242371

URL: http://svn.apache.org/viewvc?rev=1242371&view=rev
Log:
Fix a couple of issues with the UserDataHelper
1. Packaging. It should have been packaged with juli-adapters.jar. The
class has been moved so this is no longer an issue.
2. The wrong class/method was reported if the extras were used. The
logging code has been pushed back to the caller. In return for a small
amount of code duplication, the caller class/method will now always be
correct.

Added:
    tomcat/trunk/java/org/apache/tomcat/util/log/UserDataHelper.java
      - copied, changed from r1242370, tomcat/trunk/java/org/apache/juli/logging/UserDataHelper.java
Removed:
    tomcat/trunk/java/org/apache/juli/logging/UserDataHelper.java
Modified:
    tomcat/trunk/build.xml
    tomcat/trunk/java/org/apache/juli/logging/DirectJDKLog.java
    tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java
    tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java

Modified: tomcat/trunk/build.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/build.xml?rev=1242371&r1=1242370&r2=1242371&view=diff
==============================================================================
--- tomcat/trunk/build.xml (original)
+++ tomcat/trunk/build.xml Thu Feb  9 16:08:49 2012
@@ -1248,7 +1248,6 @@
       </fileset>
       <fileset dir="${tomcat.classes}">
         <include name="org/apache/juli/*" />
-        <include name="org/apache/juli/logging/UserDataHelper*.class"/>
         <!-- Javadoc and i18n exclusions -->
         <exclude name="**/package.html" />
         <exclude name="**/LocalStrings_*" />

Modified: tomcat/trunk/java/org/apache/juli/logging/DirectJDKLog.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/juli/logging/DirectJDKLog.java?rev=1242371&r1=1242370&r2=1242371&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/juli/logging/DirectJDKLog.java (original)
+++ tomcat/trunk/java/org/apache/juli/logging/DirectJDKLog.java Thu Feb  9 16:08:49 2012
@@ -172,26 +172,13 @@ class DirectJDKLog implements Log {
             Throwable dummyException=new Throwable();
             StackTraceElement locations[]=dummyException.getStackTrace();
             // Caller will be the third element (or later if logger is wrapped)
-            String cname = null;
-            String method = null;
-            if (locations != null) {
-                int i = 2;
-                while (locations.length > i) {
-                    StackTraceElement caller = locations[i];
-                    if (caller.getClassName().startsWith("org.apache.juli")) {
-                        i++;
-                    } else {
-                        cname = caller.getClassName();
-                        method = caller.getMethodName();
-                        break;
-                    }
-                }
+            String cname = "unknown";
+            String method = "unknown";
+            if (locations != null && locations.length >2) {
+                StackTraceElement caller = locations[2];
+                cname = caller.getClassName();
+                method = caller.getMethodName();
             }
-            if (cname == null) {
-                cname = "unknown";
-                method = "unknown";
-            }
-
             if (ex==null) {
                 logger.logp(level, cname, method, msg);
             } else {

Modified: tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java?rev=1242371&r1=1242370&r2=1242371&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java Thu Feb  9 16:08:49 2012
@@ -21,9 +21,9 @@ import java.io.StringWriter;
 
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
-import org.apache.juli.logging.UserDataHelper;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.MessageBytes;
+import org.apache.tomcat.util.log.UserDataHelper;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -356,11 +356,19 @@ public final class Cookies {
                         // not valid.
                         UserDataHelper.Mode logMode = userDataLog.getNextMode();
                         if (logMode != null) {
-                            String message = sm.getString("cookies.invalidCookieToken");
-                            if (logMode.fallToDebug()) {
-                                message += sm.getString("cookies.fallToDebug");
+                            String message = sm.getString(
+                                    "cookies.invalidCookieToken");
+                            switch (logMode) {
+                                case INFO_THEN_DEBUG:
+                                    message += sm.getString(
+                                            "cookies.fallToDebug");
+                                    //$FALL-THROUGH$
+                                case INFO:
+                                    log.info(message);
+                                    break;
+                                case DEBUG:
+                                    log.debug(message);
                             }
-                            userDataLog.log(logMode, message);
                         }
                         while (pos < end && bytes[pos] != ';' &&
                                bytes[pos] != ',')
@@ -445,10 +453,16 @@ public final class Cookies {
                 UserDataHelper.Mode logMode = userDataLog.getNextMode();
                 if (logMode != null) {
                     String message = sm.getString("cookies.invalidSpecial");
-                    if (logMode.fallToDebug()) {
-                        message += sm.getString("cookies.fallToDebug");
+                    switch (logMode) {
+                        case INFO_THEN_DEBUG:
+                            message += sm.getString("cookies.fallToDebug");
+                            //$FALL-THROUGH$
+                        case INFO:
+                            log.info(message);
+                            break;
+                        case DEBUG:
+                            log.debug(message);
                     }
-                    userDataLog.log(logMode, message);
                 }
             } else { // Normal Cookie
                 if (valueStart == -1 && !CookieSupport.ALLOW_NAME_ONLY) {

Modified: tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java?rev=1242371&r1=1242370&r2=1242371&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java Thu Feb  9 16:08:49 2012
@@ -25,12 +25,12 @@ import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.juli.logging.UserDataHelper;
 import org.apache.tomcat.util.buf.B2CConverter;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.CharChunk;
 import org.apache.tomcat.util.buf.MessageBytes;
 import org.apache.tomcat.util.buf.UDecoder;
+import org.apache.tomcat.util.log.UserDataHelper;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -323,10 +323,16 @@ public final class Parameters {
                     String message = sm.getString("parameters.invalidChunk",
                             Integer.valueOf(nameStart),
                             Integer.valueOf(valueEnd), extract);
-                    if (logMode.fallToDebug()) {
-                        message += sm.getString("parameters.fallToDebug");
+                    switch (logMode) {
+                        case INFO_THEN_DEBUG:
+                            message += sm.getString("parameters.fallToDebug");
+                            //$FALL-THROUGH$
+                        case INFO:
+                            log.info(message);
+                            break;
+                        case DEBUG:
+                            log.debug(message);
                     }
-                    userDataLog.log(logMode, message);
                 }
                 parseFailed = true;
                 continue;
@@ -386,10 +392,17 @@ public final class Parameters {
                     UserDataHelper.Mode logMode = maxParamCountLog.getNextMode();
                     if (logMode != null) {
                         String message = ise.getMessage();
-                        if (logMode.fallToDebug()) {
-                            message += sm.getString("parameters.maxCountFail.fallToDebug");
+                        switch (logMode) {
+                            case INFO_THEN_DEBUG:
+                                message += sm.getString(
+                                        "parameters.maxCountFail.fallToDebug");
+                                //$FALL-THROUGH$
+                            case INFO:
+                                log.info(message);
+                                break;
+                            case DEBUG:
+                                log.debug(message);
                         }
-                        maxParamCountLog.log(logMode, message);
                     }
                     break;
                 }
@@ -406,10 +419,16 @@ public final class Parameters {
                             String message = sm.getString(
                                     "parameters.decodeFail.info",
                                     tmpName.toString(), tmpValue.toString());
-                            if (logMode.fallToDebug()) {
-                                message += sm.getString("parameters.fallToDebug");
+                            switch (logMode) {
+                                case INFO_THEN_DEBUG:
+                                    message += sm.getString("parameters.fallToDebug");
+                                    //$FALL-THROUGH$
+                                case INFO:
+                                    log.info(message);
+                                    break;
+                                case DEBUG:
+                                    log.debug(message);
                             }
-                            userDataLog.log(logMode, message, e);
                         }
                     }
                 }
@@ -430,10 +449,16 @@ public final class Parameters {
                 String message = sm.getString(
                         "parameters.multipleDecodingFail",
                         Integer.valueOf(decodeFailCount));
-                if (logMode.fallToDebug()) {
-                    message += sm.getString("parameters.fallToDebug");
+                switch (logMode) {
+                    case INFO_THEN_DEBUG:
+                        message += sm.getString("parameters.fallToDebug");
+                        //$FALL-THROUGH$
+                    case INFO:
+                        log.info(message);
+                        break;
+                    case DEBUG:
+                        log.debug(message);
                 }
-                userDataLog.log(logMode, message);
             }
         }
     }

Copied: tomcat/trunk/java/org/apache/tomcat/util/log/UserDataHelper.java (from r1242370, tomcat/trunk/java/org/apache/juli/logging/UserDataHelper.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/log/UserDataHelper.java?p2=tomcat/trunk/java/org/apache/tomcat/util/log/UserDataHelper.java&p1=tomcat/trunk/java/org/apache/juli/logging/UserDataHelper.java&r1=1242370&r2=1242371&rev=1242371&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/juli/logging/UserDataHelper.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/log/UserDataHelper.java Thu Feb  9 16:08:49 2012
@@ -14,7 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.juli.logging;
+package org.apache.tomcat.util.log;
+
+import org.apache.juli.logging.Log;
 
 /**
  * This helper class assists with the logging associated with invalid input
@@ -107,36 +109,6 @@ public class UserDataHelper {
     }
 
 
-    public void log(Mode mode, String message) {
-        if (mode != null) {
-            switch (mode) {
-            case INFO:
-            case INFO_THEN_DEBUG:
-                log.info(message);
-                break;
-            case DEBUG:
-                log.debug(message);
-                break;
-            }
-        }
-    }
-
-
-    public void log(Mode mode, String message, Throwable t) {
-        if (mode != null) {
-            switch (mode) {
-            case INFO:
-            case INFO_THEN_DEBUG:
-                log.info(message, t);
-                break;
-            case DEBUG:
-                log.debug(message, t);
-                break;
-            }
-        }
-    }
-
-
     /*
      * Not completely thread-safe but good enough for this use case. I couldn't
      * see a simple enough way to make it completely thread-safe that was not



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message