Author: kkolinko
Date: Sun Dec 25 21:50:06 2011
New Revision: 1224648
URL: http://svn.apache.org/viewvc?rev=1224648&view=rev
Log:
- UserDataHelper:
1) Fix bug in suppressionTime processing. The config value is in seconds, but
time arithmetic needs msecs. Now multiplying the configured value by 1000L.
2) Change the API to allow to distinguish the case when next message will be
printed at DEBUG level.
3) The private method logAtInfo() now always updates the time. Thus I removed
its argument.
- Cookies:
1) Add i18n and print special message when we fall from INFO to DEBUG logging.
Modified:
tomcat/trunk/java/org/apache/juli/logging/UserDataHelper.java
tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java
tomcat/trunk/java/org/apache/tomcat/util/http/LocalStrings.properties
tomcat/trunk/webapps/docs/config/systemprops.xml
Modified: tomcat/trunk/java/org/apache/juli/logging/UserDataHelper.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/juli/logging/UserDataHelper.java?rev=1224648&r1=1224647&r2=1224648&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/juli/logging/UserDataHelper.java (original)
+++ tomcat/trunk/java/org/apache/juli/logging/UserDataHelper.java Sun Dec 25
21:50:06 2011
@@ -42,6 +42,7 @@ public class UserDataHelper {
// A value of 0 is equivalent to using INFO_ALL
// A negative value will trigger infinite suppression
+ // The value is milliseconds
private long suppressionTime;
private volatile long lastInfoTime = 0;
@@ -64,9 +65,9 @@ public class UserDataHelper {
}
// Default suppression time of 1 day.
- suppressionTime = Long.getLong(
+ suppressionTime = Integer.parseInt(
"org.apache.juli.logging.UserDataHelper.SUPPRESSION_TIME",
- 60 * 60 * 24).longValue();
+ 60 * 60 * 24) * 1000L;
if (suppressionTime == 0) {
config = Config.INFO_ALL;
@@ -74,55 +75,61 @@ public class UserDataHelper {
}
- public boolean isEnabled() {
+ /**
+ * Returns log mode for the next log message, or <code>null</code> if the
+ * message should not be logged.
+ *
+ * <p>
+ * If <code>INFO_THEN_DEBUG</code> configuration option is enabled, this
+ * method might change internal state of this object.
+ *
+ * @return Log mode, or <code>null</code>
+ */
+ public Mode getNextMode() {
if (Config.NONE == config) {
- return false;
+ return null;
} else if (Config.DEBUG_ALL == config) {
- return log.isDebugEnabled();
+ return log.isDebugEnabled() ? Mode.DEBUG : null;
} else if (Config.INFO_THEN_DEBUG == config) {
- if (logAtInfo(false)) {
- return log.isInfoEnabled();
+ if (logAtInfo()) {
+ return log.isInfoEnabled() ? Mode.INFO_THEN_DEBUG : null;
} else {
- return log.isDebugEnabled();
+ return log.isDebugEnabled() ? Mode.DEBUG : null;
}
} else if (Config.INFO_ALL == config) {
- return log.isInfoEnabled();
+ return log.isInfoEnabled() ? Mode.INFO : null;
}
// Should never happen
- return false;
+ return null;
}
- public void log(String message) {
- if (Config.NONE == config) {
- // NOOP;
- } else if (Config.DEBUG_ALL == config) {
- log.debug(message);
- } else if (Config.INFO_THEN_DEBUG == config) {
- if (logAtInfo(true)) {
+ public void log(Mode mode, String message) {
+ if (mode != null) {
+ switch (mode) {
+ case INFO:
+ case INFO_THEN_DEBUG:
log.info(message);
- } else {
+ break;
+ case DEBUG:
log.debug(message);
+ break;
}
- } else if (Config.INFO_ALL == config) {
- log.info(message);
}
}
- public void log(String message, Throwable t) {
- if (Config.NONE == config) {
- // NOOP;
- } else if (Config.DEBUG_ALL == config) {
- log.debug(message, t);
- } else if (Config.INFO_THEN_DEBUG == config) {
- if (logAtInfo(true)) {
+ public void log(Mode mode, String message, Throwable t) {
+ if (mode != null) {
+ switch (mode) {
+ case INFO:
+ case INFO_THEN_DEBUG:
log.info(message, t);
- } else {
+ break;
+ case DEBUG:
log.debug(message, t);
+ break;
}
- } else if (Config.INFO_ALL == config) {
- log.info(message, t);
}
}
@@ -132,7 +139,7 @@ public class UserDataHelper {
* see a simple enough way to make it completely thread-safe that was not
* likely to compromise performance.
*/
- private boolean logAtInfo(boolean updateLastLoggedTime) {
+ private boolean logAtInfo() {
if (suppressionTime < 0 && lastInfoTime > 0) {
return false;
@@ -144,9 +151,7 @@ public class UserDataHelper {
return false;
}
- if (updateLastLoggedTime) {
- lastInfoTime = now;
- }
+ lastInfoTime = now;
return true;
}
@@ -157,4 +162,21 @@ public class UserDataHelper {
INFO_THEN_DEBUG,
INFO_ALL
}
+
+ /**
+ * Log mode for the next log message.
+ */
+ public static enum Mode {
+ DEBUG(false), INFO_THEN_DEBUG(true), INFO(false);
+
+ private final boolean fallToDebug;
+
+ Mode(boolean fallToDebug) {
+ this.fallToDebug = fallToDebug;
+ }
+
+ public boolean fallToDebug() {
+ return fallToDebug;
+ }
+ }
}
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=1224648&r1=1224647&r2=1224648&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java Sun Dec 25
21:50:06 2011
@@ -24,6 +24,7 @@ import org.apache.juli.logging.LogFactor
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.res.StringManager;
/**
* A collection of cookies - reusable and tuned for server side performance.
@@ -40,6 +41,9 @@ public final class Cookies {
private static final UserDataHelper userDataLog = new UserDataHelper(log);
+ protected static final StringManager sm =
+ StringManager.getManager("org.apache.tomcat.util.http");
+
// expected average number of cookies per request
public static final int INITIAL_SIZE=4;
ServerCookie scookies[]=new ServerCookie[INITIAL_SIZE];
@@ -350,9 +354,13 @@ public final class Cookies {
// INVALID COOKIE, advance to next delimiter
// The starting character of the cookie value was
// not valid.
- if (userDataLog.isEnabled()) {
- userDataLog.log("Cookies: Invalid cookie. " +
- "Value not a token or quoted value");
+ UserDataHelper.Mode logMode =
userDataLog.getNextMode();
+ if (logMode != null) {
+ String message =
sm.getString("cookies.invalidCookieToken");
+ if (logMode.fallToDebug()) {
+ message += sm.getString("cookies.fallToDebug");
+ }
+ userDataLog.log(logMode, message);
}
while (pos < end && bytes[pos] != ';' &&
bytes[pos] != ',')
@@ -434,8 +442,13 @@ public final class Cookies {
}
// Unknown cookie, complain
- if (userDataLog.isEnabled()) {
- userDataLog.log("Cookies: Unknown Special Cookie");
+ UserDataHelper.Mode logMode = userDataLog.getNextMode();
+ if (logMode != null) {
+ String message = sm.getString("cookies.invalidSpecial");
+ if (logMode.fallToDebug()) {
+ message += sm.getString("cookies.fallToDebug");
+ }
+ userDataLog.log(logMode, message);
}
} else { // Normal Cookie
if (valueStart == -1 && !CookieSupport.ALLOW_NAME_ONLY) {
Modified: tomcat/trunk/java/org/apache/tomcat/util/http/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/LocalStrings.properties?rev=1224648&r1=1224647&r2=1224648&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/LocalStrings.properties
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/LocalStrings.properties Sun
Dec 25 21:50:06 2011
@@ -21,3 +21,7 @@ parameters.invalidChunk=Invalid chunk st
parameters.maxCountFail=More than the maximum number of request parameters
(GET plus POST) for a single request ([{0}]) were detected. Any parameters
beyond this limit have been ignored. To change this limit, set the
maxParameterCount attribute on the Connector.
parameters.multipleDecodingFail=Character decoding failed. A total of [{0}]
failures were detected but only the first was logged. Enable debug level
logging for this logger to log all failures.
parameters.noequal=Parameter starting at position [{0}] and ending at position
[{1}] with a value of [{0}] was not followed by an '=' character
+
+cookies.invalidCookieToken=Cookies: Invalid cookie. Value not a token or
quoted value
+cookies.invalidSpecial=Cookies: Unknown Special Cookie
+cookies.fallToDebug=\n Note: further occurences of Cookie errors will be
logged at DEBUG level.
Modified: tomcat/trunk/webapps/docs/config/systemprops.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/systemprops.xml?rev=1224648&r1=1224647&r2=1224648&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/systemprops.xml (original)
+++ tomcat/trunk/webapps/docs/config/systemprops.xml Sun Dec 25 21:50:06 2011
@@ -511,7 +511,8 @@
property controls how long messages are logged at DEBUG after a
message
has been logged at INFO. Once this period has elapsed, the next
message
will be logged at INFO followed by a new suppression period where
- messages are logged at DEBUG and so on.</p>
+ messages are logged at DEBUG and so on. The value is measured
+ in seconds.</p>
<p>A value of <code>0</code> is equivalent to using <code>INFO_ALL</code>
for <code>org.apache.juli.logging.UserDataHelper.CONFIG</code>.</p>
<p>A negative value means an infinite suppression period.</p>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]