Author: markt
Date: Tue Aug 2 21:27:35 2016
New Revision: 1755005
URL: http://svn.apache.org/viewvc?rev=1755005&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=59871
Make timestamp format of OneLineFormatter configurable
Modified:
tomcat/trunk/java/org/apache/juli/DateFormatCache.java
tomcat/trunk/java/org/apache/juli/OneLineFormatter.java
Modified: tomcat/trunk/java/org/apache/juli/DateFormatCache.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/juli/DateFormatCache.java?rev=1755005&r1=1755004&r2=1755005&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/juli/DateFormatCache.java (original)
+++ tomcat/trunk/java/org/apache/juli/DateFormatCache.java Tue Aug 2 21:27:35
2016
@@ -95,6 +95,10 @@ public class DateFormatCache {
return cache.getFormat(time);
}
+ public String getTimeFormat() {
+ return format;
+ }
+
private class Cache {
/* Second formatted in most recent invocation */
Modified: tomcat/trunk/java/org/apache/juli/OneLineFormatter.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/juli/OneLineFormatter.java?rev=1755005&r1=1755004&r2=1755005&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/juli/OneLineFormatter.java (original)
+++ tomcat/trunk/java/org/apache/juli/OneLineFormatter.java Tue Aug 2 21:27:35
2016
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.juli;
import java.io.PrintWriter;
@@ -26,6 +25,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Formatter;
+import java.util.logging.LogManager;
import java.util.logging.LogRecord;
/**
@@ -62,7 +62,7 @@ public class OneLineFormatter extends Fo
};
/* Timestamp format */
- private static final String timeFormat = "dd-MMM-yyyy HH:mm:ss";
+ private static final String DEFAULT_TIME_FORMAT = "dd-MMM-yyyy HH:mm:ss";
/**
* The size of our global date format cache
@@ -75,21 +75,47 @@ public class OneLineFormatter extends Fo
private static final int localCacheSize = 5;
/**
- * Global date format cache.
+ * Thread local date format cache.
*/
- private static final DateFormatCache globalDateCache =
- new DateFormatCache(globalCacheSize, timeFormat, null);
+ private ThreadLocal<DateFormatCache> localDateCache;
+
+
+ public OneLineFormatter() {
+ String timeFormat = LogManager.getLogManager().getProperty(
+ OneLineFormatter.class.getName() + ".timeFormat");
+ if (timeFormat == null) {
+ timeFormat = DEFAULT_TIME_FORMAT;
+ }
+ setTimeFormat(timeFormat);
+ }
+
/**
- * Thread local date format cache.
+ * Specify the time format to use for time stamps in log messages.
+ *
+ * @param timeFormat The format to use using the
+ * {@link java.text.SimpleDateFormat} syntax
*/
- private static final ThreadLocal<DateFormatCache> localDateCache =
- new ThreadLocal<DateFormatCache>() {
- @Override
- protected DateFormatCache initialValue() {
- return new DateFormatCache(localCacheSize, timeFormat,
globalDateCache);
- }
- };
+ public void setTimeFormat(String timeFormat) {
+ DateFormatCache globalDateCache = new DateFormatCache(globalCacheSize,
timeFormat, null);
+ localDateCache = new ThreadLocal<DateFormatCache>() {
+ @Override
+ protected DateFormatCache initialValue() {
+ return new DateFormatCache(localCacheSize, timeFormat,
globalDateCache);
+ }
+ };
+ }
+
+
+ /**
+ * Obtain the format currently being used for time stamps in log messages.
+ *
+ * @return The current format in {@link java.text.SimpleDateFormat} syntax
+ */
+ public String getTimeFormat() {
+ return localDateCache.get().getTimeFormat();
+ }
+
@Override
public String format(LogRecord record) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]