You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2018/03/13 07:04:30 UTC
[02/27] logging-chainsaw git commit: Reformat code for consistency
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/spi/SimpleULogger.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/log4j/spi/SimpleULogger.java b/src/main/java/org/apache/log4j/spi/SimpleULogger.java
index 5303c72..b05cbff 100644
--- a/src/main/java/org/apache/log4j/spi/SimpleULogger.java
+++ b/src/main/java/org/apache/log4j/spi/SimpleULogger.java
@@ -28,17 +28,17 @@ import org.apache.log4j.helpers.MessageFormatter;
* logger name, and the message followed by the line separator for the host.
* In log4j terms it amounts to the "%r [%t] %level %logger - %m%n" pattern.
* <pre>
-176 [main] INFO examples.Sort - Populating an array of 2 elements in reverse.
-225 [main] INFO examples.SortAlgo - Entered the sort method.
-304 [main] INFO SortAlgo.DUMP - Dump of interger array:
-317 [main] INFO SortAlgo.DUMP - Element [0] = 0
-331 [main] INFO SortAlgo.DUMP - Element [1] = 1
-343 [main] INFO examples.Sort - The next log statement should be an error msg.
-346 [main] ERROR SortAlgo.DUMP - Tried to dump an uninitialized array.
- at org.log4j.examples.SortAlgo.dump(SortAlgo.java:58)
- at org.log4j.examples.Sort.main(Sort.java:64)
-467 [main] INFO examples.Sort - Exiting main method.
-</pre>
+ * 176 [main] INFO examples.Sort - Populating an array of 2 elements in reverse.
+ * 225 [main] INFO examples.SortAlgo - Entered the sort method.
+ * 304 [main] INFO SortAlgo.DUMP - Dump of interger array:
+ * 317 [main] INFO SortAlgo.DUMP - Element [0] = 0
+ * 331 [main] INFO SortAlgo.DUMP - Element [1] = 1
+ * 343 [main] INFO examples.Sort - The next log statement should be an error msg.
+ * 346 [main] ERROR SortAlgo.DUMP - Tried to dump an uninitialized array.
+ * at org.log4j.examples.SortAlgo.dump(SortAlgo.java:58)
+ * at org.log4j.examples.Sort.main(Sort.java:64)
+ * 467 [main] INFO examples.Sort - Exiting main method.
+ * </pre>
*
* @author Ceki Gülcü
*/
@@ -47,259 +47,261 @@ public final class SimpleULogger implements ULogger {
/**
* Logger name.
*/
- private final String loggerName;
+ private final String loggerName;
- /**
- * Mark the time when this class gets loaded into memory.
- */
- private static long startTime = System.currentTimeMillis();
+ /**
+ * Mark the time when this class gets loaded into memory.
+ */
+ private static long startTime = System.currentTimeMillis();
/**
* Line separator.
*/
- public static final String LINE_SEPARATOR
- = System.getProperty("line.separator");
+ public static final String LINE_SEPARATOR
+ = System.getProperty("line.separator");
/**
* INFO string literal.
*/
- private static final String INFO_STR = "INFO";
+ private static final String INFO_STR = "INFO";
/**
* WARN string literal.
*/
- private static final String WARN_STR = "WARN";
+ private static final String WARN_STR = "WARN";
/**
* ERROR string literal.
*/
- private static final String ERROR_STR = "ERROR";
-
- /**
- * Constructor is private to force construction through getLogger.
- * @param name logger name
- */
- private SimpleULogger(final String name) {
- super();
- this.loggerName = name;
- }
-
- /**
- * Creates a new instance.
- *
- * @param name logger name
- * @return logger.
- */
- public static SimpleULogger getLogger(final String name) {
- return new SimpleULogger(name);
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isDebugEnabled() {
- return false;
- }
+ private static final String ERROR_STR = "ERROR";
+
+ /**
+ * Constructor is private to force construction through getLogger.
+ *
+ * @param name logger name
+ */
+ private SimpleULogger(final String name) {
+ super();
+ this.loggerName = name;
+ }
+
+ /**
+ * Creates a new instance.
+ *
+ * @param name logger name
+ * @return logger.
+ */
+ public static SimpleULogger getLogger(final String name) {
+ return new SimpleULogger(name);
+ }
/**
* {@inheritDoc}
*/
- public void debug(final Object msg) {
- // NOP
- }
+ public boolean isDebugEnabled() {
+ return false;
+ }
/**
* {@inheritDoc}
*/
- public void debug(final Object parameterizedMsg, final Object param1) {
- // NOP
- }
+ public void debug(final Object msg) {
+ // NOP
+ }
/**
* {@inheritDoc}
*/
- public void debug(final String parameterizedMsg,
- final Object param1,
- final Object param2) {
- // NOP
- }
+ public void debug(final Object parameterizedMsg, final Object param1) {
+ // NOP
+ }
/**
* {@inheritDoc}
*/
- public void debug(final Object msg, final Throwable t) {
- // NOP
- }
-
- /**
- * This is our internal implementation for logging regular (non-parameterized)
- * log messages.
- *
- * @param level level
- * @param message message
- * @param t throwable
- */
- private void log(final String level,
- final String message,
- final Throwable t) {
- StringBuilder buf = new StringBuilder();
-
- long millis = System.currentTimeMillis();
- buf.append(millis - startTime);
-
- buf.append(" [");
- buf.append(Thread.currentThread().getName());
- buf.append("] ");
-
- buf.append(level);
- buf.append(" ");
-
- buf.append(loggerName);
- buf.append(" - ");
-
- buf.append(message);
-
- buf.append(LINE_SEPARATOR);
-
- System.out.print(buf.toString());
- if (t != null) {
- t.printStackTrace(System.out);
+ public void debug(final String parameterizedMsg,
+ final Object param1,
+ final Object param2) {
+ // NOP
}
- System.out.flush();
- }
- /**
- * For parameterized messages, first substitute parameters and then log.
- *
- * @param level level
- * @param parameterizedMsg message pattern
- * @param param1 param1
- * @param param2 param2
- */
- private void parameterizedLog(final String level,
- final Object parameterizedMsg,
- final Object param1,
- final Object param2) {
- if (parameterizedMsg instanceof String) {
- String msgStr = (String) parameterizedMsg;
- msgStr = MessageFormatter.format(msgStr, param1, param2);
- log(level, msgStr, null);
- } else {
- // To be failsafe, we handle the case where 'messagePattern' is not
- // a String. Unless the user makes a mistake, this should not happen.
- log(level, parameterizedMsg.toString(), null);
+
+ /**
+ * {@inheritDoc}
+ */
+ public void debug(final Object msg, final Throwable t) {
+ // NOP
+ }
+
+ /**
+ * This is our internal implementation for logging regular (non-parameterized)
+ * log messages.
+ *
+ * @param level level
+ * @param message message
+ * @param t throwable
+ */
+ private void log(final String level,
+ final String message,
+ final Throwable t) {
+ StringBuilder buf = new StringBuilder();
+
+ long millis = System.currentTimeMillis();
+ buf.append(millis - startTime);
+
+ buf.append(" [");
+ buf.append(Thread.currentThread().getName());
+ buf.append("] ");
+
+ buf.append(level);
+ buf.append(" ");
+
+ buf.append(loggerName);
+ buf.append(" - ");
+
+ buf.append(message);
+
+ buf.append(LINE_SEPARATOR);
+
+ System.out.print(buf.toString());
+ if (t != null) {
+ t.printStackTrace(System.out);
+ }
+ System.out.flush();
+ }
+
+ /**
+ * For parameterized messages, first substitute parameters and then log.
+ *
+ * @param level level
+ * @param parameterizedMsg message pattern
+ * @param param1 param1
+ * @param param2 param2
+ */
+ private void parameterizedLog(final String level,
+ final Object parameterizedMsg,
+ final Object param1,
+ final Object param2) {
+ if (parameterizedMsg instanceof String) {
+ String msgStr = (String) parameterizedMsg;
+ msgStr = MessageFormatter.format(msgStr, param1, param2);
+ log(level, msgStr, null);
+ } else {
+ // To be failsafe, we handle the case where 'messagePattern' is not
+ // a String. Unless the user makes a mistake, this should not happen.
+ log(level, parameterizedMsg.toString(), null);
+ }
}
- }
/**
* {@inheritDoc}
*/
- public boolean isInfoEnabled() {
- return true;
- }
+ public boolean isInfoEnabled() {
+ return true;
+ }
/**
* {@inheritDoc}
*/
- public void info(final Object msg) {
- log(INFO_STR, msg.toString(), null);
- }
+ public void info(final Object msg) {
+ log(INFO_STR, msg.toString(), null);
+ }
/**
* {@inheritDoc}
*/
- public void info(final Object parameterizedMsg, final Object param1) {
- parameterizedLog(INFO_STR, parameterizedMsg, param1, null);
- }
+ public void info(final Object parameterizedMsg, final Object param1) {
+ parameterizedLog(INFO_STR, parameterizedMsg, param1, null);
+ }
/**
* {@inheritDoc}
*/
- public void info(final String parameterizedMsg,
- final Object param1,
- final Object param2) {
- parameterizedLog(INFO_STR, parameterizedMsg, param1, param2);
- }
+ public void info(final String parameterizedMsg,
+ final Object param1,
+ final Object param2) {
+ parameterizedLog(INFO_STR, parameterizedMsg, param1, param2);
+ }
/**
* {@inheritDoc}
*/
- public void info(final Object msg, final Throwable t) {
- log(INFO_STR, msg.toString(), t);
- }
+ public void info(final Object msg, final Throwable t) {
+ log(INFO_STR, msg.toString(), t);
+ }
/**
* {@inheritDoc}
*/
- public boolean isWarnEnabled() {
- return true;
- }
+ public boolean isWarnEnabled() {
+ return true;
+ }
/**
* {@inheritDoc}
*/
- public void warn(final Object msg) {
- log(WARN_STR, msg.toString(), null);
- }
+ public void warn(final Object msg) {
+ log(WARN_STR, msg.toString(), null);
+ }
/**
* {@inheritDoc}
*/
- public void warn(final Object parameterizedMsg, final Object param1) {
- parameterizedLog(WARN_STR, parameterizedMsg, param1, null);
- }
+ public void warn(final Object parameterizedMsg, final Object param1) {
+ parameterizedLog(WARN_STR, parameterizedMsg, param1, null);
+ }
/**
* {@inheritDoc}
*/
- public void warn(final String parameterizedMsg,
- final Object param1,
- final Object param2) {
- parameterizedLog(WARN_STR, parameterizedMsg, param1, param2);
- }
+ public void warn(final String parameterizedMsg,
+ final Object param1,
+ final Object param2) {
+ parameterizedLog(WARN_STR, parameterizedMsg, param1, param2);
+ }
/**
* {@inheritDoc}
*/
- public void warn(final Object msg, final Throwable t) {
- log(WARN_STR, msg.toString(), t);
- }
+ public void warn(final Object msg, final Throwable t) {
+ log(WARN_STR, msg.toString(), t);
+ }
/**
* {@inheritDoc}
*/
- public boolean isErrorEnabled() {
- return true;
- }
+ public boolean isErrorEnabled() {
+ return true;
+ }
/**
* {@inheritDoc}
*/
- public void error(final Object msg) {
- log(ERROR_STR, msg.toString(), null);
- }
+ public void error(final Object msg) {
+ log(ERROR_STR, msg.toString(), null);
+ }
/**
* {@inheritDoc}
*/
- public void error(final Object parameterizedMsg, final Object param1) {
- parameterizedLog(ERROR_STR, parameterizedMsg, param1, null);
- }
+ public void error(final Object parameterizedMsg, final Object param1) {
+ parameterizedLog(ERROR_STR, parameterizedMsg, param1, null);
+ }
/**
* {@inheritDoc}
*/
- public void error(final String parameterizedMsg,
- final Object param1,
- final Object param2) {
- parameterizedLog(ERROR_STR, parameterizedMsg, param1, param2);
- }
+ public void error(final String parameterizedMsg,
+ final Object param1,
+ final Object param2) {
+ parameterizedLog(ERROR_STR, parameterizedMsg, param1, param2);
+ }
/**
* {@inheritDoc}
*/
- public void error(final Object msg, final Throwable t) {
- log(ERROR_STR, msg.toString(), t);
- }
+ public void error(final Object msg, final Throwable t) {
+ log(ERROR_STR, msg.toString(), t);
+ }
}
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/spi/Thresholdable.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/log4j/spi/Thresholdable.java b/src/main/java/org/apache/log4j/spi/Thresholdable.java
index 222345f..8292504 100644
--- a/src/main/java/org/apache/log4j/spi/Thresholdable.java
+++ b/src/main/java/org/apache/log4j/spi/Thresholdable.java
@@ -52,7 +52,7 @@ public interface Thresholdable {
*
* @param level The level to test against the component threshold.
* @return boolean True if level is equal or greater than the
- * component threshold.
+ * component threshold.
*/
boolean isAsSevereAsThreshold(Level level);
}
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/varia/ListModelAppender.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/log4j/varia/ListModelAppender.java b/src/main/java/org/apache/log4j/varia/ListModelAppender.java
index 46ab7fc..8b9f79a 100644
--- a/src/main/java/org/apache/log4j/varia/ListModelAppender.java
+++ b/src/main/java/org/apache/log4j/varia/ListModelAppender.java
@@ -20,60 +20,64 @@ package org.apache.log4j.varia;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;
-import javax.swing.DefaultListModel;
-import javax.swing.ListModel;
+import javax.swing.*;
/**
* A very basic appender that takes the events and stores them in to a
* ListModel for late retrieval.
*
- *
* @author Paul Smith (psmith@apache.org)
- *
*/
public final class ListModelAppender extends AppenderSkeleton {
/**
* Default list model.
*/
- private final DefaultListModel<LoggingEvent> model = new DefaultListModel<>();
+ private final DefaultListModel<LoggingEvent> model = new DefaultListModel<>();
- /**
- * Constructs a ListModelAppender.
- */
- public ListModelAppender() {
- super(true);
- }
- /**
- * Returns a reference to the ListModel that contains all the LoggingEvents
- * that have been appended to this class.
- *
- * @return the list model
- */
- public ListModel<LoggingEvent> getModel() {
- return model;
- }
+ /**
+ * Constructs a ListModelAppender.
+ */
+ public ListModelAppender() {
+ super(true);
+ }
- /** {@inheritDoc} */
- protected void append(final LoggingEvent event) {
- model.addElement(event);
- }
+ /**
+ * Returns a reference to the ListModel that contains all the LoggingEvents
+ * that have been appended to this class.
+ *
+ * @return the list model
+ */
+ public ListModel<LoggingEvent> getModel() {
+ return model;
+ }
- /** {@inheritDoc} */
- public void close() {
- clearModel();
- }
+ /**
+ * {@inheritDoc}
+ */
+ protected void append(final LoggingEvent event) {
+ model.addElement(event);
+ }
- /**
- * Removes all the Events from the model.
- */
- public void clearModel() {
- model.clear();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void close() {
+ clearModel();
+ }
- /** {@inheritDoc} */
- public boolean requiresLayout() {
- return false;
- }
+ /**
+ * Removes all the Events from the model.
+ */
+ public void clearModel() {
+ model.clear();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean requiresLayout() {
+ return false;
+ }
}
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java b/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
index 8aa53bc..c6d9acb 100644
--- a/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
+++ b/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,25 +17,6 @@
package org.apache.log4j.varia;
-import java.io.BufferedReader;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.regex.MatchResult;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.helpers.Constants;
@@ -46,13 +27,23 @@ import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ThrowableInformation;
+import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.regex.MatchResult;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
/**
* LogFilePatternReceiver can parse and tail log files, converting entries into
* LoggingEvents. If the file doesn't exist when the receiver is initialized, the
* receiver will look for the file once every 10 seconds.
* <p>
* This receiver relies on java.util.regex features to perform the parsing of text in the
- * log file, however the only regular expression field explicitly supported is
+ * log file, however the only regular expression field explicitly supported is
* a glob-style wildcard used to ignore fields in the log file if needed. All other
* fields are parsed by using the supplied keywords.
* <p>
@@ -63,9 +54,9 @@ import org.apache.log4j.spi.ThrowableInformation;
* - 'tail' the file (allows the contents of the file to be continually read and new events processed)<br>
* - supports the parsing of multi-line messages and exceptions
* - 'hostname' property set to URL host (or 'file' if not available)
- * - 'application' property set to URL path (or value of fileURL if not available)
+ * - 'application' property set to URL path (or value of fileURL if not available)
* - 'group' property can be set to associate multiple log file receivers
- *<p>
+ * <p>
* <b>Keywords:</b><br>
* TIMESTAMP<br>
* LOGGER<br>
@@ -88,159 +79,159 @@ import org.apache.log4j.spi.ThrowableInformation;
* Example:<br>
* If your file's patternlayout is this:<br>
* <b>%d %-5p [%t] %C{2} (%F:%L) - %m%n</b>
- *<p>
+ * <p>
* specify this as the log format:<br>
* <b>TIMESTAMP LEVEL [THREAD] CLASS (FILE:LINE) - MESSAGE</b>
- *<p>
+ * <p>
* To define a PROPERTY field, use PROP(key)
* <p>
- * Example:<br>
- * If you used the RELATIVETIME pattern layout character in the file,
- * you can use PROP(RELATIVETIME) in the logFormat definition to assign
+ * Example:<br>
+ * If you used the RELATIVETIME pattern layout character in the file,
+ * you can use PROP(RELATIVETIME) in the logFormat definition to assign
* the RELATIVETIME field as a property on the event.
* <p>
* If your file's patternlayout is this:<br>
* <b>%r [%t] %-5p %c %x - %m%n</b>
- *<p>
+ * <p>
* specify this as the log format:<br>
* <b>PROP(RELATIVETIME) [THREAD] LEVEL LOGGER * - MESSAGE</b>
* <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 the following 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.
- *<p>
+ * <p>
* <b>Limitations:</b><br>
* - no support for the single-line version of throwable supported by patternlayout<br>
- * (this version of throwable will be included as the last line of the message)<br>
+ * (this version of throwable will be included as the last line of the message)<br>
* - the relativetime patternLayout character must be set as a property: PROP(RELATIVETIME)<br>
* - messages should appear as the last field of the logFormat because the variability in message content<br>
* - exceptions are converted if the exception stack trace (other than the first line of the exception)<br>
- * is stored in the log file with a tab followed by the word 'at' as the first characters in the line<br>
- * - tailing may fail if the file rolls over.
- *<p>
+ * is stored in the log file with a tab followed by the word 'at' as the first characters in the line<br>
+ * - tailing may fail if the file rolls over.
+ * <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="PROP(RELATIVETIME) [THREAD] LEVEL LOGGER * - MESSAGE"<br>
* param: "fileURL" value="file:///c:/events.log"<br>
* param: "tailing" value="true"
- *<p>
+ * <p>
* This configuration will be able to process these sample events:<br>
* 710 [ Thread-0] DEBUG first.logger first - <test> <test2>something here</test2> <test3 blah=something/> <test4> <test5>something else</test5> </test4></test><br>
* 880 [ Thread-2] DEBUG first.logger third - <test> <test2>something here</test2> <test3 blah=something/> <test4> <test5>something else</test5> </test4></test><br>
* 880 [ Thread-0] INFO first.logger first - infomsg-0<br>
* java.lang.Exception: someexception-first<br>
- * at Generator2.run(Generator2.java:102)<br>
+ * at Generator2.run(Generator2.java:102)<br>
*
- *@author Scott Deboy
+ * @author Scott Deboy
*/
public class LogFilePatternReceiver extends Receiver {
- private final List<String> keywords = new ArrayList<>();
-
- private static final String PROP_START = "PROP(";
- private static final String PROP_END = ")";
-
- private static final String LOGGER = "LOGGER";
- private static final String MESSAGE = "MESSAGE";
- private static final String TIMESTAMP = "TIMESTAMP";
- private static final String NDC = "NDC";
- private static final String LEVEL = "LEVEL";
- private static final String THREAD = "THREAD";
- private static final String CLASS = "CLASS";
- private static final String FILE = "FILE";
- private static final String LINE = "LINE";
- private static final String METHOD = "METHOD";
- private static final String NEWLINE = "(NL)";
-
- private static final String DEFAULT_HOST = "file";
-
- //all lines other than first line of exception begin with tab followed by 'at' followed by text
- private static final String EXCEPTION_PATTERN = "^\\s+at.*";
- private static final String REGEXP_DEFAULT_WILDCARD = ".*?";
- private static final String REGEXP_GREEDY_WILDCARD = ".*";
- private static final String PATTERN_WILDCARD = "*";
- //pull in optional leading and trailing spaces
- private static final String NOSPACE_GROUP = "(\\s*?\\S*?\\s*?)";
- private static final String DEFAULT_GROUP = "(" + REGEXP_DEFAULT_WILDCARD + ")";
- private static final String GREEDY_GROUP = "(" + REGEXP_GREEDY_WILDCARD + ")";
- private static final String MULTIPLE_SPACES_REGEXP = "[ ]+";
- private static final String NEWLINE_REGEXP = "\n";
- private final String newLine = System.getProperty("line.separator");
-
- private final String[] emptyException = new String[] { "" };
-
- private SimpleDateFormat dateFormat;
- private String timestampFormat;
- private String logFormat;
- private String customLevelDefinitions;
- private String fileURL;
- private String host;
- private String path;
- private boolean tailing;
- private String filterExpression;
- private long waitMillis = 2000; //default 2 seconds
- private String group;
-
- private static final String VALID_DATEFORMAT_CHARS = "GyYMwWDdFEuaHkKhmsSzZX";
- private static final String VALID_DATEFORMAT_CHAR_PATTERN = "[" + VALID_DATEFORMAT_CHARS + "]";
-
- private Rule expressionRule;
-
- private Map currentMap;
- private List<String> additionalLines;
- private List<String> matchingKeywords;
-
- private String regexp;
- private Reader reader;
- private Pattern regexpPattern;
- private Pattern exceptionPattern;
- private String timestampPatternText;
-
- private boolean useCurrentThread;
- public static final int MISSING_FILE_RETRY_MILLIS = 10000;
- private boolean appendNonMatches;
- private final Map<String, Level> customLevelDefinitionMap = new HashMap<>();
-
- //default to one line - this number is incremented for each (NL) found in the logFormat
- private int lineCount = 1;
+ private final List<String> keywords = new ArrayList<>();
+
+ private static final String PROP_START = "PROP(";
+ private static final String PROP_END = ")";
+
+ private static final String LOGGER = "LOGGER";
+ private static final String MESSAGE = "MESSAGE";
+ private static final String TIMESTAMP = "TIMESTAMP";
+ private static final String NDC = "NDC";
+ private static final String LEVEL = "LEVEL";
+ private static final String THREAD = "THREAD";
+ private static final String CLASS = "CLASS";
+ private static final String FILE = "FILE";
+ private static final String LINE = "LINE";
+ private static final String METHOD = "METHOD";
+ private static final String NEWLINE = "(NL)";
+
+ private static final String DEFAULT_HOST = "file";
+
+ //all lines other than first line of exception begin with tab followed by 'at' followed by text
+ private static final String EXCEPTION_PATTERN = "^\\s+at.*";
+ private static final String REGEXP_DEFAULT_WILDCARD = ".*?";
+ private static final String REGEXP_GREEDY_WILDCARD = ".*";
+ private static final String PATTERN_WILDCARD = "*";
+ //pull in optional leading and trailing spaces
+ private static final String NOSPACE_GROUP = "(\\s*?\\S*?\\s*?)";
+ private static final String DEFAULT_GROUP = "(" + REGEXP_DEFAULT_WILDCARD + ")";
+ private static final String GREEDY_GROUP = "(" + REGEXP_GREEDY_WILDCARD + ")";
+ private static final String MULTIPLE_SPACES_REGEXP = "[ ]+";
+ private static final String NEWLINE_REGEXP = "\n";
+ private final String newLine = System.getProperty("line.separator");
+
+ private final String[] emptyException = new String[]{""};
+
+ private SimpleDateFormat dateFormat;
+ private String timestampFormat;
+ private String logFormat;
+ private String customLevelDefinitions;
+ private String fileURL;
+ private String host;
+ private String path;
+ private boolean tailing;
+ private String filterExpression;
+ private long waitMillis = 2000; //default 2 seconds
+ private String group;
+
+ private static final String VALID_DATEFORMAT_CHARS = "GyYMwWDdFEuaHkKhmsSzZX";
+ private static final String VALID_DATEFORMAT_CHAR_PATTERN = "[" + VALID_DATEFORMAT_CHARS + "]";
+
+ private Rule expressionRule;
+
+ private Map currentMap;
+ private List<String> additionalLines;
+ private List<String> matchingKeywords;
+
+ private String regexp;
+ private Reader reader;
+ private Pattern regexpPattern;
+ private Pattern exceptionPattern;
+ private String timestampPatternText;
+
+ private boolean useCurrentThread;
+ public static final int MISSING_FILE_RETRY_MILLIS = 10000;
+ private boolean appendNonMatches;
+ private final Map<String, Level> customLevelDefinitionMap = new HashMap<>();
+
+ //default to one line - this number is incremented for each (NL) found in the logFormat
+ private int lineCount = 1;
public LogFilePatternReceiver() {
- keywords.add(TIMESTAMP);
- keywords.add(LOGGER);
- keywords.add(LEVEL);
- keywords.add(THREAD);
- keywords.add(CLASS);
- keywords.add(FILE);
- keywords.add(LINE);
- keywords.add(METHOD);
- keywords.add(MESSAGE);
- keywords.add(NDC);
- try {
- exceptionPattern = Pattern.compile(EXCEPTION_PATTERN);
- } catch (PatternSyntaxException pse) {
- //shouldn't happen
+ keywords.add(TIMESTAMP);
+ keywords.add(LOGGER);
+ keywords.add(LEVEL);
+ keywords.add(THREAD);
+ keywords.add(CLASS);
+ keywords.add(FILE);
+ keywords.add(LINE);
+ keywords.add(METHOD);
+ keywords.add(MESSAGE);
+ keywords.add(NDC);
+ try {
+ exceptionPattern = Pattern.compile(EXCEPTION_PATTERN);
+ } catch (PatternSyntaxException pse) {
+ //shouldn't happen
+ }
+ }
+
+ /**
+ * Accessor
+ *
+ * @return file URL
+ */
+ public String getFileURL() {
+ return fileURL;
+ }
+
+ /**
+ * Mutator
+ *
+ * @param fileURL
+ */
+ public void setFileURL(String fileURL) {
+ this.fileURL = fileURL;
}
- }
-
- /**
- * Accessor
- *
- * @return file URL
- */
- public String getFileURL() {
- return fileURL;
- }
-
- /**
- * Mutator
- *
- * @param fileURL
- */
- public void setFileURL(String fileURL) {
- this.fileURL = fileURL;
- }
/**
* If the log file contains non-log4j level strings, they can be mapped to log4j levels using the format (android example):
@@ -248,268 +239,276 @@ public class LogFilePatternReceiver extends Receiver {
*
* @param customLevelDefinitions the level definition string
*/
- public void setCustomLevelDefinitions(String customLevelDefinitions) {
- this.customLevelDefinitions = customLevelDefinitions;
- }
-
- public String getCustomLevelDefinitions() {
- return customLevelDefinitions;
- }
-
- /**
- * Accessor
- * @return append non matches
- */
- public boolean isAppendNonMatches() {
- return appendNonMatches;
- }
-
- /**
- * Mutator
- * @param appendNonMatches
- */
- public void setAppendNonMatches(boolean appendNonMatches) {
- this.appendNonMatches = appendNonMatches;
- }
-
- /**
- * Accessor
- *
- * @return filter expression
- */
- public String getFilterExpression() {
- return filterExpression;
- }
-
- /**
- * Mutator
- *
- * @param filterExpression
- */
- public void setFilterExpression(String filterExpression) {
- this.filterExpression = filterExpression;
- }
-
- /**
- * Accessor
- *
- * @return tailing
- */
- public boolean isTailing() {
- return tailing;
- }
-
- /**
- * Mutator
- *
- * @param tailing
- */
- public void setTailing(boolean tailing) {
- this.tailing = tailing;
- }
-
- /**
- * When true, this property uses the current Thread to perform the import,
- * otherwise when false (the default), a new Thread is created and started to manage
- * the import.
- * @return
- */
- public final boolean isUseCurrentThread() {
- return useCurrentThread;
- }
-
- /**
- * Sets whether the current Thread or a new Thread is created to perform the import,
- * the default being false (new Thread created).
- *
- * @param useCurrentThread
- */
- public final void setUseCurrentThread(boolean useCurrentThread) {
- this.useCurrentThread = useCurrentThread;
- }
-
- /**
- * Accessor
- *
- * @return log format
- */
- public String getLogFormat() {
- return logFormat;
- }
+ public void setCustomLevelDefinitions(String customLevelDefinitions) {
+ this.customLevelDefinitions = customLevelDefinitions;
+ }
+
+ public String getCustomLevelDefinitions() {
+ return customLevelDefinitions;
+ }
/**
- * Mutator
- *
- * @param logFormat
- * the format
- */
- public void setLogFormat(String logFormat) {
- this.logFormat = logFormat;
- }
+ * Accessor
+ *
+ * @return append non matches
+ */
+ public boolean isAppendNonMatches() {
+ return appendNonMatches;
+ }
/**
- * Mutator
- */
- public void setGroup(String group) { this.group = group; }
+ * Mutator
+ *
+ * @param appendNonMatches
+ */
+ public void setAppendNonMatches(boolean appendNonMatches) {
+ this.appendNonMatches = appendNonMatches;
+ }
+ /**
+ * Accessor
+ *
+ * @return filter expression
+ */
+ public String getFilterExpression() {
+ return filterExpression;
+ }
/**
- * Accessor
- *
- * @return group
- */
- public String getGroup() { return group; }
-
+ * Mutator
+ *
+ * @param filterExpression
+ */
+ public void setFilterExpression(String filterExpression) {
+ this.filterExpression = filterExpression;
+ }
+
/**
- * Mutator. Specify a pattern from {@link java.text.SimpleDateFormat}
- *
- * @param timestampFormat
- */
- public void setTimestampFormat(String timestampFormat) {
- this.timestampFormat = timestampFormat;
- }
+ * Accessor
+ *
+ * @return tailing
+ */
+ public boolean isTailing() {
+ return tailing;
+ }
/**
- * Accessor
- *
- * @return timestamp format
- */
- public String getTimestampFormat() {
- return timestampFormat;
- }
-
- /**
- * Accessor
- * @return millis between retrieves of content
- */
- public long getWaitMillis() {
- return waitMillis;
- }
-
- /**
- * Mutator
- * @param waitMillis
- */
- public void setWaitMillis(long waitMillis) {
- this.waitMillis = waitMillis;
- }
+ * Mutator
+ *
+ * @param tailing
+ */
+ public void setTailing(boolean tailing) {
+ this.tailing = tailing;
+ }
/**
- * Walk the additionalLines list, looking for the EXCEPTION_PATTERN.
- * <p>
- * Return the index of the first matched line
- * (the match may be the 1st line of an exception)
- * <p>
- * Assumptions: <br>
- * - the additionalLines list may contain both message and exception lines<br>
- * - message lines are added to the additionalLines list and then
- * exception lines (all message lines occur in the list prior to all
- * exception lines)
- *
- * @return -1 if no exception line exists, line number otherwise
- */
- private int getExceptionLine() {
- for (int i = 0; i < additionalLines.size(); i++) {
- Matcher exceptionMatcher = exceptionPattern.matcher(additionalLines.get(i));
- if (exceptionMatcher.matches()) {
- return i;
- }
+ * When true, this property uses the current Thread to perform the import,
+ * otherwise when false (the default), a new Thread is created and started to manage
+ * the import.
+ *
+ * @return
+ */
+ public final boolean isUseCurrentThread() {
+ return useCurrentThread;
}
- return -1;
- }
/**
- * Combine all message lines occuring in the additionalLines list, adding
- * a newline character between each line
- * <p>
- * the event will already have a message - combine this message
- * with the message lines in the additionalLines list
- * (all entries prior to the exceptionLine index)
- *
- * @param firstMessageLine primary message line
- * @param exceptionLine index of first exception line
- * @return message
- */
- private String buildMessage(String firstMessageLine, int exceptionLine) {
- if (additionalLines.size() == 0) {
- return firstMessageLine;
+ * Sets whether the current Thread or a new Thread is created to perform the import,
+ * the default being false (new Thread created).
+ *
+ * @param useCurrentThread
+ */
+ public final void setUseCurrentThread(boolean useCurrentThread) {
+ this.useCurrentThread = useCurrentThread;
}
- StringBuilder message = new StringBuilder();
- if (firstMessageLine != null) {
- message.append(firstMessageLine);
+
+ /**
+ * Accessor
+ *
+ * @return log format
+ */
+ public String getLogFormat() {
+ return logFormat;
+ }
+
+ /**
+ * Mutator
+ *
+ * @param logFormat the format
+ */
+ public void setLogFormat(String logFormat) {
+ this.logFormat = logFormat;
+ }
+
+ /**
+ * Mutator
+ */
+ public void setGroup(String group) {
+ this.group = group;
+ }
+
+
+ /**
+ * Accessor
+ *
+ * @return group
+ */
+ public String getGroup() {
+ return group;
+ }
+
+ /**
+ * Mutator. Specify a pattern from {@link java.text.SimpleDateFormat}
+ *
+ * @param timestampFormat
+ */
+ public void setTimestampFormat(String timestampFormat) {
+ this.timestampFormat = timestampFormat;
}
- int linesToProcess = (exceptionLine == -1?additionalLines.size(): exceptionLine);
+ /**
+ * Accessor
+ *
+ * @return timestamp format
+ */
+ public String getTimestampFormat() {
+ return timestampFormat;
+ }
- for (int i = 0; i < linesToProcess; i++) {
- message.append(newLine);
- message.append(additionalLines.get(i));
+ /**
+ * Accessor
+ *
+ * @return millis between retrieves of content
+ */
+ public long getWaitMillis() {
+ return waitMillis;
}
- return message.toString();
- }
/**
- * Combine all exception lines occuring in the additionalLines list into a
- * String array
- * <p>
- * (all entries equal to or greater than the exceptionLine index)
- *
- * @param exceptionLine index of first exception line
- * @return exception
- */
- private String[] buildException(int exceptionLine) {
- if (exceptionLine == -1) {
- return emptyException;
+ * Mutator
+ *
+ * @param waitMillis
+ */
+ public void setWaitMillis(long waitMillis) {
+ this.waitMillis = waitMillis;
}
- String[] exception = new String[additionalLines.size() - exceptionLine - 1];
- for (int i = 0; i < exception.length; i++) {
- exception[i] = additionalLines.get(i + exceptionLine);
+
+ /**
+ * Walk the additionalLines list, looking for the EXCEPTION_PATTERN.
+ * <p>
+ * Return the index of the first matched line
+ * (the match may be the 1st line of an exception)
+ * <p>
+ * Assumptions: <br>
+ * - the additionalLines list may contain both message and exception lines<br>
+ * - message lines are added to the additionalLines list and then
+ * exception lines (all message lines occur in the list prior to all
+ * exception lines)
+ *
+ * @return -1 if no exception line exists, line number otherwise
+ */
+ private int getExceptionLine() {
+ for (int i = 0; i < additionalLines.size(); i++) {
+ Matcher exceptionMatcher = exceptionPattern.matcher(additionalLines.get(i));
+ if (exceptionMatcher.matches()) {
+ return i;
+ }
+ }
+ return -1;
}
- return exception;
- }
/**
- * Construct a logging event from currentMap and additionalLines
- * (additionalLines contains multiple message lines and any exception lines)
- * <p>
- * CurrentMap and additionalLines are cleared in the process
- *
- * @return event
- */
- private LoggingEvent buildEvent() {
- if (currentMap.size() == 0) {
- if (additionalLines.size() > 0) {
- for (Object additionalLine : additionalLines) {
- getLogger().debug("found non-matching line: " + additionalLine);
- }
- }
- additionalLines.clear();
- return null;
+ * Combine all message lines occuring in the additionalLines list, adding
+ * a newline character between each line
+ * <p>
+ * the event will already have a message - combine this message
+ * with the message lines in the additionalLines list
+ * (all entries prior to the exceptionLine index)
+ *
+ * @param firstMessageLine primary message line
+ * @param exceptionLine index of first exception line
+ * @return message
+ */
+ private String buildMessage(String firstMessageLine, int exceptionLine) {
+ if (additionalLines.size() == 0) {
+ return firstMessageLine;
+ }
+ StringBuilder message = new StringBuilder();
+ if (firstMessageLine != null) {
+ message.append(firstMessageLine);
+ }
+
+ int linesToProcess = (exceptionLine == -1 ? additionalLines.size() : exceptionLine);
+
+ for (int i = 0; i < linesToProcess; i++) {
+ message.append(newLine);
+ message.append(additionalLines.get(i));
+ }
+ return message.toString();
}
- //the current map contains fields - build an event
- int exceptionLine = getExceptionLine();
- String[] exception = buildException(exceptionLine);
-
- //messages are listed before exceptions in additionallines
- if (additionalLines.size() > 0 && exception.length > 0) {
- currentMap.put(MESSAGE, buildMessage((String) currentMap.get(MESSAGE),
- exceptionLine));
+
+ /**
+ * Combine all exception lines occuring in the additionalLines list into a
+ * String array
+ * <p>
+ * (all entries equal to or greater than the exceptionLine index)
+ *
+ * @param exceptionLine index of first exception line
+ * @return exception
+ */
+ private String[] buildException(int exceptionLine) {
+ if (exceptionLine == -1) {
+ return emptyException;
+ }
+ String[] exception = new String[additionalLines.size() - exceptionLine - 1];
+ for (int i = 0; i < exception.length; i++) {
+ exception[i] = additionalLines.get(i + exceptionLine);
+ }
+ return exception;
}
- LoggingEvent event = convertToEvent(currentMap, exception);
- currentMap.clear();
- additionalLines.clear();
- return event;
- }
/**
- * Read, parse and optionally tail the log file, converting entries into logging events.
- *
- * A runtimeException is thrown if the logFormat pattern is malformed.
- *
- * @param bufferedReader
- * @throws IOException
- */
- protected void process(BufferedReader bufferedReader) throws IOException {
+ * Construct a logging event from currentMap and additionalLines
+ * (additionalLines contains multiple message lines and any exception lines)
+ * <p>
+ * CurrentMap and additionalLines are cleared in the process
+ *
+ * @return event
+ */
+ private LoggingEvent buildEvent() {
+ if (currentMap.size() == 0) {
+ if (additionalLines.size() > 0) {
+ for (Object additionalLine : additionalLines) {
+ getLogger().debug("found non-matching line: " + additionalLine);
+ }
+ }
+ additionalLines.clear();
+ return null;
+ }
+ //the current map contains fields - build an event
+ int exceptionLine = getExceptionLine();
+ String[] exception = buildException(exceptionLine);
+
+ //messages are listed before exceptions in additionallines
+ if (additionalLines.size() > 0 && exception.length > 0) {
+ currentMap.put(MESSAGE, buildMessage((String) currentMap.get(MESSAGE),
+ exceptionLine));
+ }
+ LoggingEvent event = convertToEvent(currentMap, exception);
+ currentMap.clear();
+ additionalLines.clear();
+ return event;
+ }
+
+ /**
+ * Read, parse and optionally tail the log file, converting entries into logging events.
+ * <p>
+ * A runtimeException is thrown if the logFormat pattern is malformed.
+ *
+ * @param bufferedReader
+ * @throws IOException
+ */
+ protected void process(BufferedReader bufferedReader) throws IOException {
Matcher eventMatcher;
Matcher exceptionMatcher;
String readLine;
@@ -517,18 +516,18 @@ public class LogFilePatternReceiver extends Receiver {
while ((readLine = bufferedReader.readLine()) != null) {
StringBuilder line = new StringBuilder(readLine);
//there is already one line (read above, start i at 1
- for (int i=1;i<lineCount;i++)
- {
+ for (int i = 1; i < lineCount; i++) {
String thisLine = bufferedReader.readLine();
- if (thisLine != null)
- {
- line.append(newLine).append(thisLine);
+ if (thisLine != null) {
+ line.append(newLine).append(thisLine);
}
}
String input = line.toString();
eventMatcher = regexpPattern.matcher(input);
//skip empty line entries
- if (input.trim().equals("")) {continue;}
+ if (input.trim().equals("")) {
+ continue;
+ }
exceptionMatcher = exceptionPattern.matcher(input);
if (eventMatcher.matches()) {
//build an event from the previous match (held in current map)
@@ -549,13 +548,13 @@ public class LogFilePatternReceiver extends Receiver {
//choice is to have each non-matching line show up as its own line, or append them all to a previous event
if (appendNonMatches) {
//hold on to the previous time, so we can do our best to preserve time-based ordering if the event is a non-match
- String lastTime = (String)currentMap.get(TIMESTAMP);
+ String lastTime = (String) currentMap.get(TIMESTAMP);
//build an event from the previous match (held in current map)
if (currentMap.size() > 0) {
LoggingEvent event = buildEvent();
if (event != null) {
if (passesExpression(event)) {
- doPost(event);
+ doPost(event);
}
}
}
@@ -583,210 +582,208 @@ public class LogFilePatternReceiver extends Receiver {
}
/**
- * Helper method that supports the evaluation of the expression
- *
- * @param event
- * @return true if expression isn't set, or the result of the evaluation otherwise
- */
- private boolean passesExpression(LoggingEvent event) {
- if (event != null) {
- if (expressionRule != null) {
- return (expressionRule.evaluate(event, null));
- }
+ * Helper method that supports the evaluation of the expression
+ *
+ * @param event
+ * @return true if expression isn't set, or the result of the evaluation otherwise
+ */
+ private boolean passesExpression(LoggingEvent event) {
+ if (event != null) {
+ if (expressionRule != null) {
+ return (expressionRule.evaluate(event, null));
+ }
+ }
+ return true;
}
- return true;
- }
/**
- * Convert the match into a map.
- * <p>
- * Relies on the fact that the matchingKeywords list is in the same
- * order as the groups in the regular expression
- *
- * @param result
- * @return map
- */
- private Map processEvent(MatchResult result) {
- Map map = new HashMap();
- //group zero is the entire match - process all other groups
- for (int i = 1; i < result.groupCount() + 1; i++) {
- Object key = matchingKeywords.get(i - 1);
- Object value = result.group(i);
- map.put(key, value);
+ * Convert the match into a map.
+ * <p>
+ * Relies on the fact that the matchingKeywords list is in the same
+ * order as the groups in the regular expression
+ *
+ * @param result
+ * @return map
+ */
+ private Map processEvent(MatchResult result) {
+ Map map = new HashMap();
+ //group zero is the entire match - process all other groups
+ for (int i = 1; i < result.groupCount() + 1; i++) {
+ Object key = matchingKeywords.get(i - 1);
+ Object value = result.group(i);
+ map.put(key, value);
+ }
+ return map;
}
- return map;
- }
/**
- * Helper method that will convert timestamp format to a pattern
- *
- *
- * @return string
- */
- private String convertTimestamp() {
- //some locales (for example, French) generate timestamp text with characters not included in \w -
- // now using \S (all non-whitespace characters) instead of /w
- String result = "";
- if (timestampFormat != null) {
- result = timestampFormat.replaceAll(Pattern.quote("+"), "[+]");
- result = result.replaceAll(VALID_DATEFORMAT_CHAR_PATTERN, "\\\\S+");
- //make sure dots in timestamp are escaped
- result = result.replaceAll(Pattern.quote("."), "\\\\.");
+ * Helper method that will convert timestamp format to a pattern
+ *
+ * @return string
+ */
+ private String convertTimestamp() {
+ //some locales (for example, French) generate timestamp text with characters not included in \w -
+ // now using \S (all non-whitespace characters) instead of /w
+ String result = "";
+ if (timestampFormat != null) {
+ result = timestampFormat.replaceAll(Pattern.quote("+"), "[+]");
+ result = result.replaceAll(VALID_DATEFORMAT_CHAR_PATTERN, "\\\\S+");
+ //make sure dots in timestamp are escaped
+ result = result.replaceAll(Pattern.quote("."), "\\\\.");
+ }
+ return result;
}
- return result;
- }
protected void setHost(String host) {
- this.host = host;
- }
+ this.host = host;
+ }
protected void setPath(String path) {
- this.path = path;
- }
+ this.path = path;
+ }
- public String getPath() {
- return path;
- }
+ public String getPath() {
+ return path;
+ }
/**
- * Build the regular expression needed to parse log entries
- *
- */
- protected void initialize() {
- if (host == null && path == null) {
- try {
- URL url = new URL(fileURL);
- host = url.getHost();
- path = url.getPath();
- } catch (MalformedURLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- if (host == null || host.trim().equals("")) {
- host = DEFAULT_HOST;
- }
- if (path == null || path.trim().equals("")) {
- path = fileURL;
- }
-
- currentMap = new HashMap();
- additionalLines = new ArrayList<>();
- matchingKeywords = new ArrayList<>();
-
- if (timestampFormat != null) {
- dateFormat = new SimpleDateFormat(quoteTimeStampChars(timestampFormat));
- timestampPatternText = convertTimestamp();
- }
- //if custom level definitions exist, parse them
- updateCustomLevelDefinitionMap();
- try {
- if (filterExpression != null) {
- expressionRule = ExpressionRule.getRule(filterExpression);
- }
- } catch (Exception e) {
- getLogger().warn("Invalid filter expression: " + filterExpression, e);
- }
+ * Build the regular expression needed to parse log entries
+ */
+ protected void initialize() {
+ if (host == null && path == null) {
+ try {
+ URL url = new URL(fileURL);
+ host = url.getHost();
+ path = url.getPath();
+ } catch (MalformedURLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+ if (host == null || host.trim().equals("")) {
+ host = DEFAULT_HOST;
+ }
+ if (path == null || path.trim().equals("")) {
+ path = fileURL;
+ }
- List<String> buildingKeywords = new ArrayList<>();
+ currentMap = new HashMap();
+ additionalLines = new ArrayList<>();
+ matchingKeywords = new ArrayList<>();
- String newPattern = logFormat;
+ if (timestampFormat != null) {
+ dateFormat = new SimpleDateFormat(quoteTimeStampChars(timestampFormat));
+ timestampPatternText = convertTimestamp();
+ }
+ //if custom level definitions exist, parse them
+ updateCustomLevelDefinitionMap();
+ try {
+ if (filterExpression != null) {
+ expressionRule = ExpressionRule.getRule(filterExpression);
+ }
+ } catch (Exception e) {
+ getLogger().warn("Invalid filter expression: " + filterExpression, e);
+ }
- //process newlines - (NL) - in the logFormat - before processing properties
- int index = 0;
- while (index > -1) {
- index = newPattern.indexOf(NEWLINE);
- if (index > -1) {
- //keep track of number of expected newlines in the format, so the lines can be concatenated prior to matching
- lineCount++;
- newPattern = singleReplace(newPattern, NEWLINE, NEWLINE_REGEXP);
- }
- }
-
- String current = newPattern;
- //build a list of property names and temporarily replace the property with an empty string,
- //we'll rebuild the pattern later
- List<String> propertyNames = new ArrayList<>();
- index = 0;
- while (index > -1) {
- if (current.contains(PROP_START) && current.contains(PROP_END)) {
- index = current.indexOf(PROP_START);
- String longPropertyName = current.substring(current.indexOf(PROP_START), current.indexOf(PROP_END) + 1);
- String shortProp = getShortPropertyName(longPropertyName);
- buildingKeywords.add(shortProp);
- propertyNames.add(longPropertyName);
- current = current.substring(longPropertyName.length() + 1 + index);
- newPattern = singleReplace(newPattern, longPropertyName, Integer.toString(buildingKeywords.size() - 1));
- } else {
- //no properties
- index = -1;
+ List<String> buildingKeywords = new ArrayList<>();
+
+ String newPattern = logFormat;
+
+ //process newlines - (NL) - in the logFormat - before processing properties
+ int index = 0;
+ while (index > -1) {
+ index = newPattern.indexOf(NEWLINE);
+ if (index > -1) {
+ //keep track of number of expected newlines in the format, so the lines can be concatenated prior to matching
+ lineCount++;
+ newPattern = singleReplace(newPattern, NEWLINE, NEWLINE_REGEXP);
+ }
}
- }
- /*
- * we're using a treemap, so the index will be used as the key to ensure
- * keywords are ordered correctly
- *
- * examine pattern, adding keywords to an index-based map patterns can
- * contain only one of these per entry...properties are the only 'keyword'
- * that can occur multiple times in an entry
- */
- for (Object keyword1 : keywords) {
- String keyword = (String) keyword1;
- int index2 = newPattern.indexOf(keyword);
- if (index2 > -1) {
- buildingKeywords.add(keyword);
- newPattern = singleReplace(newPattern, keyword, Integer.toString(buildingKeywords.size() - 1));
- }
- }
-
- StringBuilder buildingInt = new StringBuilder();
-
- for (int i=0;i<newPattern.length();i++) {
- String thisValue = String.valueOf(newPattern.substring(i, i+1));
- if (isInteger(thisValue)) {
- buildingInt.append(thisValue);
- } else {
- String stringInt = buildingInt.toString();
- if (isInteger(stringInt)) {
- matchingKeywords.add(buildingKeywords.get(Integer.parseInt(stringInt)));
+ String current = newPattern;
+ //build a list of property names and temporarily replace the property with an empty string,
+ //we'll rebuild the pattern later
+ List<String> propertyNames = new ArrayList<>();
+ index = 0;
+ while (index > -1) {
+ if (current.contains(PROP_START) && current.contains(PROP_END)) {
+ index = current.indexOf(PROP_START);
+ String longPropertyName = current.substring(current.indexOf(PROP_START), current.indexOf(PROP_END) + 1);
+ String shortProp = getShortPropertyName(longPropertyName);
+ buildingKeywords.add(shortProp);
+ propertyNames.add(longPropertyName);
+ current = current.substring(longPropertyName.length() + 1 + index);
+ newPattern = singleReplace(newPattern, longPropertyName, Integer.toString(buildingKeywords.size() - 1));
+ } else {
+ //no properties
+ index = -1;
}
- //reset
- buildingInt.setLength(0);
}
- }
- //if the very last value is an int, make sure to add it
- String stringInt = buildingInt.toString();
- if (isInteger(stringInt)) {
- matchingKeywords.add(buildingKeywords.get(Integer.parseInt(stringInt)));
- }
+ /*
+ * we're using a treemap, so the index will be used as the key to ensure
+ * keywords are ordered correctly
+ *
+ * examine pattern, adding keywords to an index-based map patterns can
+ * contain only one of these per entry...properties are the only 'keyword'
+ * that can occur multiple times in an entry
+ */
+ for (Object keyword1 : keywords) {
+ String keyword = (String) keyword1;
+ int index2 = newPattern.indexOf(keyword);
+ if (index2 > -1) {
+ buildingKeywords.add(keyword);
+ newPattern = singleReplace(newPattern, keyword, Integer.toString(buildingKeywords.size() - 1));
+ }
+ }
- newPattern = replaceMetaChars(newPattern);
-
- //compress one or more spaces in the pattern into the [ ]+ regexp
- //(supports padding of level in log files)
- newPattern = newPattern.replaceAll(MULTIPLE_SPACES_REGEXP, MULTIPLE_SPACES_REGEXP);
- newPattern = newPattern.replaceAll(Pattern.quote(PATTERN_WILDCARD), REGEXP_DEFAULT_WILDCARD);
- //use buildingKeywords here to ensure correct order
- for (int i = 0;i<buildingKeywords.size();i++) {
- String keyword = buildingKeywords.get(i);
- //make the final keyword greedy (we're assuming it's the message)
- if (i == (buildingKeywords.size() - 1)) {
- newPattern = singleReplace(newPattern, String.valueOf(i), GREEDY_GROUP);
- } else if (TIMESTAMP.equals(keyword)) {
- newPattern = singleReplace(newPattern, String.valueOf(i), "(" + timestampPatternText + ")");
- } else if (LOGGER.equals(keyword) || LEVEL.equals(keyword)) {
- newPattern = singleReplace(newPattern, String.valueOf(i), NOSPACE_GROUP);
- } else {
- newPattern = singleReplace(newPattern, String.valueOf(i), DEFAULT_GROUP);
- }
- }
+ StringBuilder buildingInt = new StringBuilder();
+
+ for (int i = 0; i < newPattern.length(); i++) {
+ String thisValue = String.valueOf(newPattern.substring(i, i + 1));
+ if (isInteger(thisValue)) {
+ buildingInt.append(thisValue);
+ } else {
+ String stringInt = buildingInt.toString();
+ if (isInteger(stringInt)) {
+ matchingKeywords.add(buildingKeywords.get(Integer.parseInt(stringInt)));
+ }
+ //reset
+ buildingInt.setLength(0);
+ }
+ }
- regexp = newPattern;
- getLogger().debug("regexp is " + regexp);
- }
+ //if the very last value is an int, make sure to add it
+ String stringInt = buildingInt.toString();
+ if (isInteger(stringInt)) {
+ matchingKeywords.add(buildingKeywords.get(Integer.parseInt(stringInt)));
+ }
+
+ newPattern = replaceMetaChars(newPattern);
+
+ //compress one or more spaces in the pattern into the [ ]+ regexp
+ //(supports padding of level in log files)
+ newPattern = newPattern.replaceAll(MULTIPLE_SPACES_REGEXP, MULTIPLE_SPACES_REGEXP);
+ newPattern = newPattern.replaceAll(Pattern.quote(PATTERN_WILDCARD), REGEXP_DEFAULT_WILDCARD);
+ //use buildingKeywords here to ensure correct order
+ for (int i = 0; i < buildingKeywords.size(); i++) {
+ String keyword = buildingKeywords.get(i);
+ //make the final keyword greedy (we're assuming it's the message)
+ if (i == (buildingKeywords.size() - 1)) {
+ newPattern = singleReplace(newPattern, String.valueOf(i), GREEDY_GROUP);
+ } else if (TIMESTAMP.equals(keyword)) {
+ newPattern = singleReplace(newPattern, String.valueOf(i), "(" + timestampPatternText + ")");
+ } else if (LOGGER.equals(keyword) || LEVEL.equals(keyword)) {
+ newPattern = singleReplace(newPattern, String.valueOf(i), NOSPACE_GROUP);
+ } else {
+ newPattern = singleReplace(newPattern, String.valueOf(i), DEFAULT_GROUP);
+ }
+ }
+
+ regexp = newPattern;
+ getLogger().debug("regexp is " + regexp);
+ }
private void updateCustomLevelDefinitionMap() {
if (customLevelDefinitions != null) {
@@ -814,7 +811,7 @@ public class LogFilePatternReceiver extends Receiver {
StringBuilder result = new StringBuilder();
//ok to default to false because we also check for index zero below
boolean lastCharIsDateFormat = false;
- for (int i = 0;i<input.length();i++) {
+ 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
@@ -835,17 +832,14 @@ public class LogFilePatternReceiver extends Receiver {
return result.toString();
}
- private String singleReplace(String inputString, String oldString, String newString)
- {
+ private String singleReplace(String inputString, String oldString, String newString) {
int propLength = oldString.length();
int startPos = inputString.indexOf(oldString);
- if (startPos == -1)
- {
+ if (startPos == -1) {
getLogger().info("string: " + oldString + " not found in input: " + inputString + " - returning input");
return inputString;
}
- if (startPos == 0)
- {
+ if (startPos == 0) {
inputString = inputString.substring(propLength);
inputString = newString + inputString;
} else {
@@ -854,149 +848,147 @@ public class LogFilePatternReceiver extends Receiver {
return inputString;
}
- private String getShortPropertyName(String longPropertyName)
- {
- String currentProp = longPropertyName.substring(longPropertyName.indexOf(PROP_START));
- String prop = currentProp.substring(0, currentProp.indexOf(PROP_END) + 1);
- String shortProp = prop.substring(PROP_START.length(), prop.length() - 1);
- return shortProp;
- }
+ private String getShortPropertyName(String longPropertyName) {
+ String currentProp = longPropertyName.substring(longPropertyName.indexOf(PROP_START));
+ String prop = currentProp.substring(0, currentProp.indexOf(PROP_END) + 1);
+ String shortProp = prop.substring(PROP_START.length(), prop.length() - 1);
+ return shortProp;
+ }
/**
- * Some perl5 characters may occur in the log file format.
- * Escape these characters to prevent parsing errors.
- *
- * @param input
- * @return string
- */
- private String replaceMetaChars(String input) {
- //escape backslash first since that character is used to escape the remaining meta chars
- input = input.replaceAll("\\\\", "\\\\\\");
-
- //don't escape star - it's used as the wildcard
- input = input.replaceAll(Pattern.quote("]"), "\\\\]");
- input = input.replaceAll(Pattern.quote("["), "\\\\[");
- input = input.replaceAll(Pattern.quote("^"), "\\\\^");
- input = input.replaceAll(Pattern.quote("$"), "\\\\$");
- input = input.replaceAll(Pattern.quote("."), "\\\\.");
- input = input.replaceAll(Pattern.quote("|"), "\\\\|");
- input = input.replaceAll(Pattern.quote("?"), "\\\\?");
- input = input.replaceAll(Pattern.quote("+"), "\\\\+");
- input = input.replaceAll(Pattern.quote("("), "\\\\(");
- input = input.replaceAll(Pattern.quote(")"), "\\\\)");
- input = input.replaceAll(Pattern.quote("-"), "\\\\-");
- input = input.replaceAll(Pattern.quote("{"), "\\\\{");
- input = input.replaceAll(Pattern.quote("}"), "\\\\}");
- input = input.replaceAll(Pattern.quote("#"), "\\\\#");
- return input;
- }
+ * Some perl5 characters may occur in the log file format.
+ * Escape these characters to prevent parsing errors.
+ *
+ * @param input
+ * @return string
+ */
+ private String replaceMetaChars(String input) {
+ //escape backslash first since that character is used to escape the remaining meta chars
+ input = input.replaceAll("\\\\", "\\\\\\");
+
+ //don't escape star - it's used as the wildcard
+ input = input.replaceAll(Pattern.quote("]"), "\\\\]");
+ input = input.replaceAll(Pattern.quote("["), "\\\\[");
+ input = input.replaceAll(Pattern.quote("^"), "\\\\^");
+ input = input.replaceAll(Pattern.quote("$"), "\\\\$");
+ input = input.replaceAll(Pattern.quote("."), "\\\\.");
+ input = input.replaceAll(Pattern.quote("|"), "\\\\|");
+ input = input.replaceAll(Pattern.quote("?"), "\\\\?");
+ input = input.replaceAll(Pattern.quote("+"), "\\\\+");
+ input = input.replaceAll(Pattern.quote("("), "\\\\(");
+ input = input.replaceAll(Pattern.quote(")"), "\\\\)");
+ input = input.replaceAll(Pattern.quote("-"), "\\\\-");
+ input = input.replaceAll(Pattern.quote("{"), "\\\\{");
+ input = input.replaceAll(Pattern.quote("}"), "\\\\}");
+ input = input.replaceAll(Pattern.quote("#"), "\\\\#");
+ return input;
+ }
/**
- * Convert a keyword-to-values map to a LoggingEvent
- *
- * @param fieldMap
- * @param exception
- *
- * @return logging event
- */
- private LoggingEvent convertToEvent(Map fieldMap, String[] exception) {
- if (fieldMap == null) {
- return null;
- }
+ * Convert a keyword-to-values map to a LoggingEvent
+ *
+ * @param fieldMap
+ * @param exception
+ * @return logging event
+ */
+ private LoggingEvent convertToEvent(Map fieldMap, String[] exception) {
+ if (fieldMap == null) {
+ return null;
+ }
- //a logger must exist at a minimum for the event to be processed
- if (!fieldMap.containsKey(LOGGER)) {
- fieldMap.put(LOGGER, "Unknown");
- }
- if (exception == null) {
- exception = emptyException;
- }
+ //a logger must exist at a minimum for the event to be processed
+ if (!fieldMap.containsKey(LOGGER)) {
+ fieldMap.put(LOGGER, "Unknown");
+ }
+ if (exception == null) {
+ exception = emptyException;
+ }
- Logger logger;
- long timeStamp = 0L;
- String level;
- String threadName;
- Object message;
- String ndc;
- String className;
- String methodName;
- String eventFileName;
- String lineNumber;
- Hashtable properties = new Hashtable();
-
- logger = Logger.getLogger((String) fieldMap.remove(LOGGER));
-
- if ((dateFormat != null) && fieldMap.containsKey(TIMESTAMP)) {
- try {
- timeStamp = dateFormat.parse((String) fieldMap.remove(TIMESTAMP))
- .getTime();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- //use current time if timestamp not parseable/dateformat not specified
- if (timeStamp == 0L) {
- timeStamp = System.currentTimeMillis();
- }
+ Logger logger;
+ long timeStamp = 0L;
+ String level;
+ String threadName;
+ Object message;
+ String ndc;
+ String className;
+ String methodName;
+ String eventFileName;
+ String lineNumber;
+ Hashtable properties = new Hashtable();
+
+ logger = Logger.getLogger((String) fieldMap.remove(LOGGER));
+
+ if ((dateFormat != null) && fieldMap.containsKey(TIMESTAMP)) {
+ try {
+ timeStamp = dateFormat.parse((String) fieldMap.remove(TIMESTAMP))
+ .getTime();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ //use current time if timestamp not parseable/dateformat not specified
+ if (timeStamp == 0L) {
+ timeStamp = System.currentTimeMillis();
+ }
- message = fieldMap.remove(MESSAGE);
- if (message == null) {
- message = "";
- }
+ message = fieldMap.remove(MESSAGE);
+ if (message == null) {
+ message = "";
+ }
- level = (String) fieldMap.remove(LEVEL);
- Level levelImpl;
- if (level == null) {
- levelImpl = Level.DEBUG;
- } else {
- //first try to resolve against custom level definition map, then fall back to regular levels
- levelImpl = customLevelDefinitionMap.get(level);
- if (levelImpl == null) {
- levelImpl = Level.toLevel(level.trim());
- if (!level.equals(levelImpl.toString())) {
- //check custom level map
- if (levelImpl == null) {
- levelImpl = Level.DEBUG;
- getLogger().debug("found unexpected level: " + level + ", logger: " + logger.getName() + ", msg: " + message);
- //make sure the text that couldn't match a level is added to the message
- message = level + " " + message;
+ level = (String) fieldMap.remove(LEVEL);
+ Level levelImpl;
+ if (level == null) {
+ levelImpl = Level.DEBUG;
+ } else {
+ //first try to resolve against custom level definition map, then fall back to regular levels
+ levelImpl = customLevelDefinitionMap.get(level);
+ if (levelImpl == null) {
+ levelImpl = Level.toLevel(level.trim());
+ if (!level.equals(levelImpl.toString())) {
+ //check custom level map
+ if (levelImpl == null) {
+ levelImpl = Level.DEBUG;
+ getLogger().debug("found unexpected level: " + level + ", logger: " + logger.getName() + ", msg: " + message);
+ //make sure the text that couldn't match a level is added to the message
+ message = level + " " + message;
+ }
}
}
}
- }
- threadName = (String) fieldMap.remove(THREAD);
+ threadName = (String) fieldMap.remove(THREAD);
- ndc = (String) fieldMap.remove(NDC);
+ ndc = (String) fieldMap.remove(NDC);
- className = (String) fieldMap.remove(CLASS);
+ className = (String) fieldMap.remove(CLASS);
- methodName = (String) fieldMap.remove(METHOD);
+ methodName = (String) fieldMap.remove(METHOD);
- eventFileName = (String) fieldMap.remove(FILE);
+ eventFileName = (String) fieldMap.remove(FILE);
- lineNumber = (String) fieldMap.remove(LINE);
+ lineNumber = (String) fieldMap.remove(LINE);
- properties.put(Constants.HOSTNAME_KEY, host);
- properties.put(Constants.APPLICATION_KEY, path);
- properties.put(Constants.RECEIVER_NAME_KEY, getName());
- if (group != null) {
- properties.put(Constants.GROUP_KEY, group);
- }
+ properties.put(Constants.HOSTNAME_KEY, host);
+ properties.put(Constants.APPLICATION_KEY, path);
+ properties.put(Constants.RECEIVER_NAME_KEY, getName());
+ if (group != null) {
+ properties.put(Constants.GROUP_KEY, group);
+ }
- //all remaining entries in fieldmap are properties
- properties.putAll(fieldMap);
+ //all remaining entries in fieldmap are properties
+ properties.putAll(fieldMap);
- LocationInfo info;
+ LocationInfo info;
- if ((eventFileName != null) || (className != null) || (methodName != null)
- || (lineNumber != null)) {
- info = new LocationInfo(eventFileName, className, methodName, lineNumber);
- } else {
- info = LocationInfo.NA_LOCATION_INFO;
- }
+ if ((eventFileName != null) || (className != null) || (methodName != null)
+ || (lineNumber != null)) {
+ info = new LocationInfo(eventFileName, className, methodName, lineNumber);
+ } else {
+ info = LocationInfo.NA_LOCATION_INFO;
+ }
- LoggingEvent event = new LoggingEvent(null,
+ LoggingEvent event = new LoggingEvent(null,
logger, timeStamp, levelImpl, message,
threadName,
new ThrowableInformation(exception),
@@ -1004,8 +996,8 @@ public class LogFilePatternReceiver extends Receiver {
info,
properties);
- return event;
- }
+ return event;
+ }
// public static void main(String[] args) {
// org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
@@ -1024,73 +1016,75 @@ public class LogFilePatternReceiver extends Receiver {
// }
/**
- * Close the reader.
- */
- public void shutdown() {
- getLogger().info(getPath() + " shutdown");
- active = false;
- try {
- if (reader != null) {
- reader.close();
- reader = null;
- }
- } catch (IOException ioe) {
- ioe.printStackTrace();
+ * Close the reader.
+ */
+ public void shutdown() {
+ getLogger().info(getPath() + " shutdown");
+ active = false;
+ try {
+ if (reader != null) {
+ reader.close();
+ reader = null;
+ }
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
}
- }
/**
- * Read and process the log file.
- */
- public void activateOptions() {
- getLogger().info("activateOptions");
- active = true;
- Runnable runnable = new Runnable() {
- public void run() {
- initialize();
- while (reader == null) {
- getLogger().info("attempting to load file: " + getFileURL());
- try {
- reader = new InputStreamReader(new URL(getFileURL()).openStream(), "UTF-8");
- } catch (FileNotFoundException fnfe) {
- getLogger().info("file not available - will try again");
- synchronized (this) {
- try {
- wait(MISSING_FILE_RETRY_MILLIS);
- } catch (InterruptedException ie) {}
- }
- } catch (IOException ioe) {
- getLogger().warn("unable to load file", ioe);
- return;
- }
- }
- try {
- BufferedReader bufferedReader = new BufferedReader(reader);
- createPattern();
- do {
- process(bufferedReader);
+ * Read and process the log file.
+ */
+ public void activateOptions() {
+ getLogger().info("activateOptions");
+ active = true;
+ Runnable runnable = new Runnable() {
+ public void run() {
+ initialize();
+ while (reader == null) {
+ getLogger().info("attempting to load file: " + getFileURL());
try {
+ reader = new InputStreamReader(new URL(getFileURL()).openStream(), "UTF-8");
+ } catch (FileNotFoundException fnfe) {
+ getLogger().info("file not available - will try again");
synchronized (this) {
- wait(waitMillis);
+ try {
+ wait(MISSING_FILE_RETRY_MILLIS);
+ } catch (InterruptedException ie) {
+ }
}
- } catch (InterruptedException ie) {}
- if (tailing) {
- getLogger().debug("tailing file");
+ } catch (IOException ioe) {
+ getLogger().warn("unable to load file", ioe);
+ return;
}
- } while (tailing);
+ }
+ try {
+ BufferedReader bufferedReader = new BufferedReader(reader);
+ createPattern();
+ do {
+ process(bufferedReader);
+ try {
+ synchronized (this) {
+ wait(waitMillis);
+ }
+ } catch (InterruptedException ie) {
+ }
+ if (tailing) {
+ getLogger().debug("tailing file");
+ }
+ } while (tailing);
- } catch (IOException ioe) {
- //io exception - probably shut down
- getLogger().info("stream closed");
+ } catch (IOException ioe) {
+ //io exception - probably shut down
+ getLogger().info("stream closed");
+ }
+ getLogger().debug("processing " + path + " complete");
+ shutdown();
}
- getLogger().debug("processing " + path + " complete");
- shutdown();
- }
};
- if(useCurrentThread) {
+ if (useCurrentThread) {
runnable.run();
- }else {
- new Thread(runnable, "LogFilePatternReceiver-"+getName()).start();
+ } else {
+ new Thread(runnable, "LogFilePatternReceiver-" + getName()).start();
}
}
}
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/varia/LogFilePatternReceiverBeanInfo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/log4j/varia/LogFilePatternReceiverBeanInfo.java b/src/main/java/org/apache/log4j/varia/LogFilePatternReceiverBeanInfo.java
index d7f0a8e..01e28c6 100644
--- a/src/main/java/org/apache/log4j/varia/LogFilePatternReceiverBeanInfo.java
+++ b/src/main/java/org/apache/log4j/varia/LogFilePatternReceiverBeanInfo.java
@@ -23,32 +23,31 @@ import java.beans.SimpleBeanInfo;
/**
* BeanInfo class for the meta-data of the LogFilePatternReceiver.
- *
*/
public class LogFilePatternReceiverBeanInfo extends SimpleBeanInfo {
- /* (non-Javadoc)
- * @see java.beans.BeanInfo#getPropertyDescriptors()
- */
- public PropertyDescriptor[] getPropertyDescriptors() {
- try {
- return new PropertyDescriptor[] {
- new PropertyDescriptor("fileURL", LogFilePatternReceiver.class),
- new PropertyDescriptor(
- "timestampFormat", LogFilePatternReceiver.class),
- new PropertyDescriptor("logFormat", LogFilePatternReceiver.class),
- new PropertyDescriptor("name", LogFilePatternReceiver.class),
- new PropertyDescriptor("tailing", LogFilePatternReceiver.class),
- new PropertyDescriptor(
- "filterExpression", LogFilePatternReceiver.class),
- new PropertyDescriptor("waitMillis", LogFilePatternReceiver.class),
- new PropertyDescriptor("appendNonMatches", LogFilePatternReceiver.class),
- new PropertyDescriptor("customLevelDefinitions", LogFilePatternReceiver.class),
- new PropertyDescriptor("useCurrentThread", LogFilePatternReceiver.class),
- new PropertyDescriptor("group", LogFilePatternReceiver.class),
- };
- } catch (Exception e) {
- }
+ /* (non-Javadoc)
+ * @see java.beans.BeanInfo#getPropertyDescriptors()
+ */
+ public PropertyDescriptor[] getPropertyDescriptors() {
+ try {
+ return new PropertyDescriptor[]{
+ new PropertyDescriptor("fileURL", LogFilePatternReceiver.class),
+ new PropertyDescriptor(
+ "timestampFormat", LogFilePatternReceiver.class),
+ new PropertyDescriptor("logFormat", LogFilePatternReceiver.class),
+ new PropertyDescriptor("name", LogFilePatternReceiver.class),
+ new PropertyDescriptor("tailing", LogFilePatternReceiver.class),
+ new PropertyDescriptor(
+ "filterExpression", LogFilePatternReceiver.class),
+ new PropertyDescriptor("waitMillis", LogFilePatternReceiver.class),
+ new PropertyDescriptor("appendNonMatches", LogFilePatternReceiver.class),
+ new PropertyDescriptor("customLevelDefinitions", LogFilePatternReceiver.class),
+ new PropertyDescriptor("useCurrentThread", LogFilePatternReceiver.class),
+ new PropertyDescriptor("group", LogFilePatternReceiver.class),
+ };
+ } catch (Exception e) {
+ }
- return null;
- }
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/xml/LogFileXMLReceiver.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/log4j/xml/LogFileXMLReceiver.java b/src/main/java/org/apache/log4j/xml/LogFileXMLReceiver.java
index 921a036..ac652ea 100644
--- a/src/main/java/org/apache/log4j/xml/LogFileXMLReceiver.java
+++ b/src/main/java/org/apache/log4j/xml/LogFileXMLReceiver.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,15 +17,6 @@
package org.apache.log4j.xml;
-import java.io.BufferedReader;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Collection;
-
import org.apache.log4j.helpers.Constants;
import org.apache.log4j.plugins.Receiver;
import org.apache.log4j.rule.ExpressionRule;
@@ -33,6 +24,11 @@ import org.apache.log4j.rule.Rule;
import org.apache.log4j.spi.Decoder;
import org.apache.log4j.spi.LoggingEvent;
+import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collection;
+
/**
* LogFileXMLReceiver will read an xml-formated log file and make the events in the log file
* available to the log4j framework.
@@ -54,7 +50,7 @@ import org.apache.log4j.spi.LoggingEvent;
* <p>
* Once the event has been "posted", it will be handled by the appenders currently configured in the
* LoggerRespository.
- *
+ *
* @author Scott Deboy <sdeboy@apache.org>
* @since 1.3
*/
@@ -75,7 +71,7 @@ public class LogFileXMLReceiver extends Receiver {
/**
* Accessor
- *
+ *
* @return file URL
*/
public String getFileURL() {
@@ -84,7 +80,7 @@ public class LogFileXMLReceiver extends Receiver {
/**
* Specify the URL of the XML-formatted file to process.
- *
+ *
* @param fileURL
*/
public void setFileURL(String fileURL) {
@@ -93,7 +89,7 @@ public class LogFileXMLReceiver extends Receiver {
/**
* Accessor
- *
+ *
* @return
*/
public String getDecoder() {
@@ -102,7 +98,7 @@ public class LogFileXMLReceiver extends Receiver {
/**
* Specify the class name implementing org.apache.log4j.spi.Decoder that can process the file.
- *
+ *
* @param _decoder
*/
public void setDecoder(String _decoder) {
@@ -111,7 +107,7 @@ public class LogFileXMLReceiver extends Receiver {
/**
* Accessor
- *
+ *
* @return filter expression
*/
public String getFilterExpression() {
@@ -120,7 +116,7 @@ public class LogFileXMLReceiver extends Receiver {
/**
* Accessor
- *
+ *
* @return tailing flag
*/
public boolean isTailing() {
@@ -130,7 +126,7 @@ public class LogFileXMLReceiver extends Receiver {
/**
* Set the 'tailing' flag - may only work on file:// URLs and may stop tailing if the writing
* process closes the file and reopens.
- *
+ *
* @param tailing
*/
public void setTailing(boolean tailing) {
@@ -140,7 +136,7 @@ public class LogFileXMLReceiver extends Receiver {
/**
* Set the filter expression that will cause only events which pass the filter to be forwarded
* to the log4j framework.
- *
+ *
* @param filterExpression
*/
public void setFilterExpression(String filterExpression) {
@@ -281,7 +277,7 @@ public class LogFileXMLReceiver extends Receiver {
/**
* When true, this property uses the current Thread to perform the import, otherwise when false
* (the default), a new Thread is created and started to manage the import.
- *
+ *
* @return
*/
public final boolean isUseCurrentThread() {
@@ -291,7 +287,7 @@ public class LogFileXMLReceiver extends Receiver {
/**
* Sets whether the current Thread or a new Thread is created to perform the import, the default
* being false (new Thread created).
- *
+ *
* @param useCurrentThread
*/
public final void setUseCurrentThread(boolean useCurrentThread) {
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java b/src/main/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java
index 71a349c..84b5632 100644
--- a/src/main/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java
+++ b/src/main/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java
@@ -26,7 +26,6 @@ import java.io.ByteArrayInputStream;
/**
* An {@link EntityResolver} specifically designed to return
* an empty InputSource for logger.dtd.
- *
*/
public final class UtilLoggingEntityResolver implements EntityResolver {
@@ -38,13 +37,15 @@ public final class UtilLoggingEntityResolver implements EntityResolver {
}
- /** {@inheritDoc} */
- public InputSource resolveEntity(final String publicId,
- final String systemId) {
- if (systemId.endsWith("logger.dtd")) {
- return new InputSource(new ByteArrayInputStream(new byte[0]));
- } else {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ public InputSource resolveEntity(final String publicId,
+ final String systemId) {
+ if (systemId.endsWith("logger.dtd")) {
+ return new InputSource(new ByteArrayInputStream(new byte[0]));
+ } else {
+ return null;
+ }
}
- }
}