changed logfilepatternreceiver parsing to use .*? and .* instead of .+? and .+
allows use of empty string matches - example: when ndc is delimited with brackets but there is no NDC value, [NDC] in the logFormat will match [] as well as [some ndc value]
I don't believe this will break existing users of LogFilePatternReceiver, since folks were unable to match fields with no text (they were required to have at least one character to have a field resolved) and this is still supported.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/companions/receivers/trunk@678623 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java b/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
index 35e4c36..7125a7f 100644
--- a/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
+++ b/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
@@ -108,7 +108,7 @@
* <p>
* Note the * - it can be used to ignore a single word or sequence of words in the log file
* (in order for the wildcard to ignore a sequence of words, the text being ignored must be
- * followed by some delimiter, like '-' or '[') - ndc is being ignored in this example.
+ * followed by some delimiter, like '-' or '[') - ndc is being ignored in the following example.
* <p>
* Assign a filterExpression in order to only process events which match a filter.
* If a filterExpression is not assigned, all events are processed.
@@ -124,7 +124,7 @@
*<p>
* <b>Example receiver configuration settings</b> (add these as params, specifying a LogFilePatternReceiver 'plugin'):<br>
* param: "timestampFormat" value="yyyy-MM-d HH:mm:ss,SSS"<br>
- * param: "logFormat" value="RELATIVETIME [THREAD] LEVEL LOGGER * - MESSAGE"<br>
+ * param: "logFormat" value="PROP(RELATIVETIME) [THREAD] LEVEL LOGGER * - MESSAGE"<br>
* param: "fileURL" value="file:///c:/events.log"<br>
* param: "tailing" value="true"
*<p>
@@ -158,8 +158,8 @@
//all lines other than first line of exception begin with tab followed by 'at' followed by text
private static final String EXCEPTION_PATTERN = "\tat.*";
- private static final String REGEXP_DEFAULT_WILDCARD = ".+?";
- private static final String REGEXP_GREEDY_WILDCARD = ".+";
+ private static final String REGEXP_DEFAULT_WILDCARD = ".*?";
+ private static final String REGEXP_GREEDY_WILDCARD = ".*";
private static final String PATTERN_WILDCARD = "*";
private static final String DEFAULT_GROUP = "(" + REGEXP_DEFAULT_WILDCARD + ")";
private static final String GREEDY_GROUP = "(" + REGEXP_GREEDY_WILDCARD + ")";
@@ -782,21 +782,23 @@
return event;
}
+ /*
public static void main(String[] args) {
- /*
+ org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
+ org.apache.log4j.ConsoleAppender appender = new org.apache.log4j.ConsoleAppender(new org.apache.log4j.SimpleLayout());
+ appender.setName("console");
+ rootLogger.addAppender(appender);
LogFilePatternReceiver test = new LogFilePatternReceiver();
- test.setLogFormat("TIMESTAMP LEVEL [THREAD] LOGGER (FILE:LINE) - MESSAGE");
- test.setTailing(true);
+ org.apache.log4j.spi.LoggerRepository repo = new org.apache.log4j.LoggerRepositoryExImpl(org.apache.log4j.LogManager.getLoggerRepository());
+ test.setLoggerRepository(repo);
+ test.setLogFormat("PROP(RELATIVETIME) [THREAD] LEVEL LOGGER * - MESSAGE");
+ test.setTailing(false);
+ test.setTimestampFormat("yyyy-MM-d HH:mm:ss,SSS");
test.setFileURL("file:///C:/log/test.log");
test.initialize();
- try {
- test.process(new InputStreamReader(new URL(test.getFileURL())
- .openStream()));
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
- */
+ test.activateOptions();
}
+ */
/**
* Close the reader.