You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by sd...@apache.org on 2010/08/14 09:42:54 UTC
svn commit: r985442 -
/logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
Author: sdeboy
Date: Sat Aug 14 07:42:54 2010
New Revision: 985442
URL: http://svn.apache.org/viewvc?rev=985442&view=rev
Log:
Support non-pattern characters in SimpleDateFormat (for example the T in 2010-08-12T13:58:50.729)
Modified:
logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
Modified: logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java?rev=985442&r1=985441&r2=985442&view=diff
==============================================================================
--- logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java (original)
+++ logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java Sat Aug 14 07:42:54 2010
@@ -181,7 +181,8 @@ public class LogFilePatternReceiver exte
private Perl5Util util = null;
private Perl5Compiler exceptionCompiler = null;
private Perl5Matcher exceptionMatcher = null;
- private static final String VALID_DATEFORMAT_CHAR_PATTERN = "[GyMwWDdFEaHkKhmsSzZ]";
+ private static final String VALID_DATEFORMAT_CHARS = "GyMwWDdFEaHkKhmsSzZ";
+ private static final String VALID_DATEFORMAT_CHAR_PATTERN = "[" + VALID_DATEFORMAT_CHARS + "]";
private Rule expressionRule;
@@ -648,7 +649,7 @@ public class LogFilePatternReceiver exte
matchingKeywords = new ArrayList();
if (timestampFormat != null) {
- dateFormat = new SimpleDateFormat(timestampFormat);
+ dateFormat = new SimpleDateFormat(quoteTimeStampChars(timestampFormat));
timestampPatternText = convertTimestamp();
}
//if custom level definitions exist, parse them
@@ -771,6 +772,32 @@ public class LogFilePatternReceiver exte
}
}
+ private String quoteTimeStampChars(String input) {
+ //put single quotes around text that isn't a supported dateformat char
+ StringBuffer result = new StringBuffer();
+ //ok to default to false because we also check for index zero below
+ boolean lastCharIsDateFormat = false;
+ for (int i = 0;i<input.length();i++) {
+ String thisVal = input.substring(i, i + 1);
+ boolean thisCharIsDateFormat = VALID_DATEFORMAT_CHARS.contains(thisVal);
+ //we have encountered a non-dateformat char
+ if (!thisCharIsDateFormat && (i == 0 || lastCharIsDateFormat)) {
+ result.append("'");
+ }
+ //we have encountered a dateformat char after previously encountering a non-dateformat char
+ if (thisCharIsDateFormat && i > 0 && !lastCharIsDateFormat) {
+ result.append("'");
+ }
+ lastCharIsDateFormat = thisCharIsDateFormat;
+ result.append(thisVal);
+ }
+ //append an end single-quote if we ended with non-dateformat char
+ if (!lastCharIsDateFormat) {
+ result.append("'");
+ }
+ return result.toString();
+ }
+
private String singleReplace(String inputString, String oldString, String newString)
{
int propLength = oldString.length();
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org