You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2011/12/28 08:50:17 UTC
svn commit: r1225138 [1/2] - in
/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core:
appender/rolling/helper/ appender/routing/ config/ config/plugins/ filter/
helpers/
Author: rgoers
Date: Wed Dec 28 07:50:16 2011
New Revision: 1225138
URL: http://svn.apache.org/viewvc?rev=1225138&view=rev
Log:
Fix more javadoc and checkstyle bugs
Modified:
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/GZCompressAction.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/ZipCompressAction.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Node.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Property.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/AppenderRefPlugin.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/AppendersPlugin.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/LoggersPlugin.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/Plugin.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAttr.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginConfiguration.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginElement.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginFactory.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginValue.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/ResolverUtil.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/FilterBase.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/Filterable.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ValueLevelPair.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/helpers/Constants.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/helpers/FileUtils.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/helpers/KeyValuePair.java
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/GZCompressAction.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/GZCompressAction.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/GZCompressAction.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/GZCompressAction.java Wed Dec 28 07:50:16 2011
@@ -28,6 +28,9 @@ import java.util.zip.GZIPOutputStream;
* Compresses a file using GZ compression.
*/
public final class GZCompressAction extends ActionBase {
+
+ private static final int BUF_SIZE = 8102;
+
/**
* Source file.
*/
@@ -43,9 +46,6 @@ public final class GZCompressAction exte
*/
private final boolean deleteSource;
- private static final int BUF_SIZE = 8102;
-
-
/**
* Create new instance of GZCompressAction.
*
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/ZipCompressAction.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/ZipCompressAction.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/ZipCompressAction.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/ZipCompressAction.java Wed Dec 28 07:50:16 2011
@@ -29,6 +29,9 @@ import java.util.zip.ZipOutputStream;
* Compresses a file using Zip compression.
*/
public final class ZipCompressAction extends ActionBase {
+
+ private static final int BUF_SIZE = 8102;
+
/**
* Source file.
*/
@@ -44,9 +47,6 @@ public final class ZipCompressAction ext
*/
private final boolean deleteSource;
- private static final int BUF_SIZE = 8102;
-
-
/**
* Create new instance of GZCompressAction.
*
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java Wed Dec 28 07:50:16 2011
@@ -195,6 +195,9 @@ public final class RoutingAppender exten
return new RoutingAppender(name, filter, handleExceptions, routes, rewritePolicy, config);
}
+ /**
+ * Wrapper to allow AppenderControl to be used here.
+ */
private static class AppenderWrapper extends AppenderControl {
public AppenderWrapper(Appender appender) {
super(appender);
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java Wed Dec 28 07:50:16 2011
@@ -51,16 +51,30 @@ import java.util.concurrent.CopyOnWriteA
* The Base Configuration. Many configuration implementations will extend this class.
*/
public class BaseConfiguration extends Filterable implements Configuration {
+ /**
+ * Allow subclasses access to the status logger without creating another instance.
+ */
+ protected static final Logger LOGGER = StatusLogger.getLogger();
- protected final static Logger LOGGER = StatusLogger.getLogger();
-
+ /**
+ * The root node of the configuration.
+ */
protected Node rootNode;
+ /**
+ * The Plugin Manager.
+ */
protected PluginManager pluginManager;
+ /**
+ * Listeners for configuration changes.
+ */
protected final List<ConfigurationListener> listeners =
new CopyOnWriteArrayList<ConfigurationListener>();
+ /**
+ * The ConfigurationMonitor that checks for configuration changes.
+ */
protected ConfigurationMonitor monitor = new DefaultConfigurationMonitor();
private String name;
@@ -92,7 +106,7 @@ public class BaseConfiguration extends F
pluginManager.collectPlugins();
setup();
doConfigure();
- for (LoggerConfig logger: loggers.values()) {
+ for (LoggerConfig logger : loggers.values()) {
logger.startFilter();
}
for (Appender appender : appenders.values()) {
@@ -142,8 +156,7 @@ public class BaseConfiguration extends F
LOGGER.error("Properties declaration must be the first element in the configuration");
}
continue;
- }
- else if (subst.getVariableResolver() == null) {
+ } else if (subst.getVariableResolver() == null) {
subst.setVariableResolver(new Interpolator(null));
}
if (child.getName().equalsIgnoreCase("appenders")) {
@@ -539,21 +552,21 @@ public class BaseConfiguration extends F
sb.append("Configuration");
}
} else if (a instanceof PluginValue) {
- String name = ((PluginValue)a).value();
+ String name = ((PluginValue) a).value();
String v = node.getValue();
if (v == null) {
v = getAttrValue("value", attrs);
}
String value = subst.replace(event, v);
- sb.append(name +"=" + "\"" + value + "\"");
+ sb.append(name).append("=\"").append(value).append("\"");
parms[index] = value;
} else if (a instanceof PluginAttr) {
- String name = ((PluginAttr)a).value();
+ String name = ((PluginAttr) a).value();
String value = subst.replace(event, getAttrValue(name, attrs));
- sb.append(name +"=" + "\"" + value + "\"");
+ sb.append(name).append("=\"").append(value).append("\"");
parms[index] = value;
} else if (a instanceof PluginElement) {
- PluginElement elem = (PluginElement)a;
+ PluginElement elem = (PluginElement) a;
String name = elem.value();
if (parmClasses[index].isArray()) {
Class parmClass = parmClasses[index].getComponentType();
@@ -574,7 +587,7 @@ public class BaseConfiguration extends F
System.out.println("Null object returned for " + child.getName());
}
if (obj.getClass().isArray()) {
- printArray(sb, (Object[])obj);
+ printArray(sb, (Object[]) obj);
parms[index] = obj;
break;
}
@@ -587,7 +600,7 @@ public class BaseConfiguration extends F
break;
}
Object[] array = (Object[]) Array.newInstance(parmClass, list.size());
- int i=0;
+ int i = 0;
for (Object obj : list) {
array[i] = obj;
++i;
@@ -652,24 +665,20 @@ public class BaseConfiguration extends F
}
}
- try
- {
+ try {
int mod = factoryMethod.getModifiers();
- if (!Modifier.isStatic(mod))
- {
+ if (!Modifier.isStatic(mod)) {
LOGGER.error(factoryMethod.getName() + " method is not static on class " +
clazz.getName() + " for element " + node.getName());
return null;
}
- LOGGER.debug("Calling " + factoryMethod.getName() + " on class " + clazz.getName() + " for element " +
- node.getName() + sb.toString());
+ LOGGER.debug("Calling {} on class {} for element {}", factoryMethod.getName(), clazz.getName(),
+ node.getName(), sb.toString());
//if (parms.length > 0) {
return factoryMethod.invoke(null, parms);
//}
//return factoryMethod.invoke(null, node);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
LOGGER.error("Unable to invoke method " + factoryMethod.getName() + " in class " +
clazz.getName() + " for element " + node.getName(), e);
}
@@ -687,7 +696,7 @@ public class BaseConfiguration extends F
}
}
- private String getAttrValue(String name, Map<String, String>attrs) {
+ private String getAttrValue(String name, Map<String, String> attrs) {
for (String key : attrs.keySet()) {
if (key.equalsIgnoreCase(name)) {
String attr = attrs.get(key);
@@ -715,4 +724,4 @@ public class BaseConfiguration extends F
}
}
}
-}
\ No newline at end of file
+}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java Wed Dec 28 07:50:16 2011
@@ -54,24 +54,41 @@ import java.util.TreeSet;
* DefaultConfiguration is always called last if no configuration has been returned.
*/
public abstract class ConfigurationFactory {
-
+ /**
+ * Allow the ConfigurationFactory class to be specified as a system property.
+ */
public static final String CONFIGURATION_FACTORY_PROPERTY = "log4j.configurationFactory";
+ /**
+ * Allow the location of the configuration file to be specified as a system property.
+ */
public static final String CONFIGURATION_FILE_PROPERTY = "log4j.configurationFile";
+ /**
+ * Allow subclasses access to the status logger without creating another instance.
+ */
protected static final Logger LOGGER = StatusLogger.getLogger();
- private static List<ConfigurationFactory> factories = new ArrayList<ConfigurationFactory>();
-
- protected File configFile = null;
-
+ /**
+ * File name prefix for test configurations.
+ */
protected static final String TEST_PREFIX = "log4j2-test";
+ /**
+ * File name prefix for standard configurations.
+ */
protected static final String DEFAULT_PREFIX = "log4j2";
+ private static List<ConfigurationFactory> factories = new ArrayList<ConfigurationFactory>();
+
private static ConfigurationFactory configFactory = new Factory();
/**
+ * The configuration File.
+ */
+ protected File configFile = null;
+
+ /**
* Return the ConfigurationFactory.
* @return the ConfigurationFactory.
*/
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java Wed Dec 28 07:50:16 2011
@@ -27,7 +27,9 @@ public class FileConfigurationMonitor im
private static final int MASK = 0x0f;
- private final static int MIN_INTERVAL = 30;
+ private static final int MIN_INTERVAL = 30;
+
+ private static final int MILLIS_PER_SECOND = 1000;
private final File file;
@@ -51,7 +53,7 @@ public class FileConfigurationMonitor im
this.file = file;
this.lastModified = file.lastModified();
this.listeners = listeners;
- this.interval = (interval < MIN_INTERVAL ? MIN_INTERVAL : interval) * 1000;
+ this.interval = (interval < MIN_INTERVAL ? MIN_INTERVAL : interval) * MILLIS_PER_SECOND;
this.nextCheck = System.currentTimeMillis() + interval;
}
@@ -60,7 +62,7 @@ public class FileConfigurationMonitor im
*/
public void checkConfiguration() {
if ((++counter & MASK) == 0) {
- synchronized(this) {
+ synchronized (this) {
long current = System.currentTimeMillis();
if (current >= nextCheck) {
nextCheck = current + interval;
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java Wed Dec 28 07:50:16 2011
@@ -42,9 +42,12 @@ import java.util.Map;
* Creates a Node hierarchy from a JSON file.
*/
public class JSONConfiguration extends BaseConfiguration {
- private List<Status> status = new ArrayList<Status>();
- private static final String[] verboseClasses = new String[] { ResolverUtil.class.getName() };
+ private static final String[] VERBOSE_CLASSES = new String[] {ResolverUtil.class.getName()};
+
+ private static final int BUF_SIZE = 16384;
+
+ private List<Status> status = new ArrayList<Status>();
private JsonNode root;
@@ -92,14 +95,14 @@ public class JSONConfiguration extends B
found = true;
((StatusConsoleListener) listener).setLevel(status);
if (!verbose) {
- ((StatusConsoleListener) listener).setFilters(verboseClasses);
+ ((StatusConsoleListener) listener).setFilters(VERBOSE_CLASSES);
}
}
}
if (!found && status != Level.OFF) {
StatusConsoleListener listener = new StatusConsoleListener(status);
if (!verbose) {
- listener.setFilters(verboseClasses);
+ listener.setFilters(VERBOSE_CLASSES);
}
((StatusLogger) LOGGER).registerListener(listener);
}
@@ -149,7 +152,7 @@ public class JSONConfiguration extends B
}
if (n.isArray()) {
LOGGER.debug("Processing node for array " + entry.getKey());
- for (int i=0; i < n.size(); ++i) {
+ for (int i = 0; i < n.size(); ++i) {
String pluginType = getType(n.get(i), entry.getKey());
PluginType entryType = getPluginManager().getPluginType(pluginType);
Node item = new Node(node, entry.getKey(), entryType);
@@ -184,7 +187,8 @@ public class JSONConfiguration extends B
t = type.getElementName() + ":" + type.getPluginClass();
}
- String p = node.getParent() == null ? "null" : node.getParent().getName() == null ? "root" : node.getParent().getName();
+ String p = node.getParent() == null ? "null" : node.getParent().getName() == null ?
+ "root" : node.getParent().getName();
LOGGER.debug("Returning " + node.getName() + " with parent " + p + " of type " + t);
return node;
}
@@ -221,7 +225,7 @@ public class JSONConfiguration extends B
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
- byte[] data = new byte[16384];
+ byte[] data = new byte[BUF_SIZE];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
@@ -230,14 +234,20 @@ public class JSONConfiguration extends B
return buffer.toByteArray();
}
- private enum ErrorType {
+ /**
+ * The error that occurred.
+ */
+ private enum ErrorType {
CLASS_NOT_FOUND
}
- private class Status {
- JsonNode node;
- String name;
- ErrorType errorType;
+ /**
+ * Status for recording errors.
+ */
+ private class Status {
+ private JsonNode node;
+ private String name;
+ private ErrorType errorType;
public Status(String name, JsonNode node, ErrorType errorType) {
this.name = name;
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java Wed Dec 28 07:50:16 2011
@@ -24,19 +24,22 @@ import java.io.File;
/**
*
*/
-@Plugin(name="JSONConfigurationFactory", type="ConfigurationFactory")
+@Plugin(name = "JSONConfigurationFactory", type = "ConfigurationFactory")
@Order(6)
public class JSONConfigurationFactory extends ConfigurationFactory {
+ /**
+ * The file extensions supported by this factory.
+ */
public static final String[] SUFFIXES = new String[] {".json", ".jsn"};
- private File configFile = null;
-
private static String[] dependencies = new String[] {
"org.codehaus.jackson.JsonNode",
"org.codehaus.jackson.map.ObjectMapper"
};
+ private File configFile = null;
+
private boolean isActive;
public JSONConfigurationFactory() {
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java Wed Dec 28 07:50:16 2011
@@ -43,10 +43,10 @@ import java.util.concurrent.ConcurrentHa
/**
* Logger object that is created via configuration.
*/
-@Plugin(name="logger",type="Core", printObject=true)
+@Plugin(name = "logger", type = "Core", printObject = true)
public class LoggerConfig extends Filterable implements LogEventFactory {
- private static Logger logger = StatusLogger.getLogger();
+ private static final Logger LOGGER = StatusLogger.getLogger();
private List<String> appenderRefs = new ArrayList<String>();
private Map<String, AppenderControl> appenders = new ConcurrentHashMap<String, AppenderControl>();
@@ -233,7 +233,7 @@ public class LoggerConfig extends Filter
}
/**
- * Logs an event/
+ * Logs an event.
* @param event Yhe log event.
*/
public void log(LogEvent event) {
@@ -250,7 +250,7 @@ public class LoggerConfig extends Filter
}
private void callAppenders(LogEvent event) {
- for (AppenderControl control: appenders.values()) {
+ for (AppenderControl control : appenders.values()) {
control.callAppender(event);
}
}
@@ -270,6 +270,7 @@ public class LoggerConfig extends Filter
return new Log4jLogEvent(loggerName, marker, fqcn, level, data, t);
}
+ @Override
public String toString() {
return name == null || name.length() == 0 ? "root" : name;
}
@@ -290,7 +291,7 @@ public class LoggerConfig extends Filter
@PluginElement("appender-ref") String[] refs,
@PluginElement("filters") Filter filter) {
if (loggerName == null) {
- logger.error("Loggers cannot be configured without a name");
+ LOGGER.error("Loggers cannot be configured without a name");
return null;
}
@@ -305,7 +306,7 @@ public class LoggerConfig extends Filter
/**
* The root Logger.
*/
- @Plugin(name = "root", type = "Core", printObject=true)
+ @Plugin(name = "root", type = "Core", printObject = true)
public static class RootLogger extends LoggerConfig {
@PluginFactory
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Node.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Node.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Node.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Node.java Wed Dec 28 07:50:16 2011
@@ -24,7 +24,7 @@ import java.util.List;
import java.util.Map;
/**
- *
+ * Represents a Configuration element.
*/
public class Node {
@@ -99,8 +99,9 @@ public class Node {
return type;
}
+ @Override
public String toString() {
return type.isObjectPrintable() ? object.toString() :
- type.getPluginClass().getName() + " with name " + name;
+ type.getPluginClass().getName() + " with name " + name;
}
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java Wed Dec 28 07:50:16 2011
@@ -19,11 +19,11 @@ package org.apache.logging.log4j.core.co
import org.apache.logging.log4j.Level;
/**
- *
+ * This configuration defaults to no logging.
*/
public class NullConfiguration extends BaseConfiguration {
- public static final String NULL_NAME = "Null";
+ private static final String NULL_NAME = "Null";
public NullConfiguration() {
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Order.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Order.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Order.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Order.java Wed Dec 28 07:50:16 2011
@@ -27,5 +27,5 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Order {
- public int value();
+ int value();
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Property.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Property.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Property.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Property.java Wed Dec 28 07:50:16 2011
@@ -24,38 +24,53 @@ import org.apache.logging.log4j.core.con
import org.apache.logging.log4j.status.StatusLogger;
/**
- *
+ * Represents a key/value pair in the configuration.
*/
@Plugin(name = "property", type = "Core", printObject = true)
-public class Property {
+public final class Property {
- protected final static Logger logger = StatusLogger.getLogger();
+ private static final Logger LOGGER = StatusLogger.getLogger();
private String name;
private String value;
- public Property(String name, String value) {
+ private Property(String name, String value) {
this.name = name;
this.value = value;
}
+ /**
+ * Return the property name.
+ * @return the property name.
+ */
public String getName() {
return name;
}
+ /**
+ * Return the property value.
+ * @return the value of the property.
+ */
public String getValue() {
return value;
}
+ /**
+ * Create a Property.
+ * @param key The key.
+ * @param value The value.
+ * @return A Property.
+ */
@PluginFactory
public static Property createProperty(@PluginAttr("name") String key,
@PluginValue("value") String value) {
if (key == null) {
- logger.error("Property key cannot be null");
+ LOGGER.error("Property key cannot be null");
}
return new Property(key, value);
}
+ @Override
public String toString() {
return name + "=" + value;
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java Wed Dec 28 07:50:16 2011
@@ -56,6 +56,12 @@ import java.util.Map;
*/
public class XMLConfiguration extends BaseConfiguration {
+ private static final String[] VERBOSE_CLASSES = new String[] {ResolverUtil.class.getName()};
+
+ private static final String LOG4J_XSD = "Log4J-V2.0.xsd";
+
+ private static final int BUF_SIZE = 16384;
+
private List<Status> status = new ArrayList<Status>();
private Element rootElement = null;
@@ -64,12 +70,8 @@ public class XMLConfiguration extends Ba
private String schema = null;
- private static final String[] verboseClasses = new String[] { ResolverUtil.class.getName() };
-
private Validator validator;
- private static final String LOG4J_XSD = "Log4J-V2.0.xsd";
-
public XMLConfiguration(InputSource source, File configFile) {
byte[] buffer = null;
@@ -114,14 +116,14 @@ public class XMLConfiguration extends Ba
found = true;
((StatusConsoleListener) listener).setLevel(status);
if (!verbose) {
- ((StatusConsoleListener)listener).setFilters(verboseClasses);
+ ((StatusConsoleListener) listener).setFilters(VERBOSE_CLASSES);
}
}
}
if (!found && status != Level.OFF) {
StatusConsoleListener listener = new StatusConsoleListener(status);
if (!verbose) {
- listener.setFilters(verboseClasses);
+ listener.setFilters(VERBOSE_CLASSES);
}
((StatusLogger) LOGGER).registerListener(listener);
}
@@ -216,7 +218,7 @@ public class XMLConfiguration extends Ba
private String getType(Element element) {
if (strict) {
NamedNodeMap attrs = element.getAttributes();
- for (int i= 0; i < attrs.getLength(); ++i) {
+ for (int i = 0; i < attrs.getLength(); ++i) {
org.w3c.dom.Node w3cNode = attrs.item(i);
if (w3cNode instanceof Attr) {
Attr attr = (Attr) w3cNode;
@@ -235,7 +237,7 @@ public class XMLConfiguration extends Ba
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
- byte[] data = new byte[16384];
+ byte[] data = new byte[BUF_SIZE];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
@@ -258,14 +260,20 @@ public class XMLConfiguration extends Ba
return attributes;
}
+ /**
+ * The error that occurred.
+ */
private enum ErrorType {
CLASS_NOT_FOUND
}
+ /**
+ * Status for recording errors.
+ */
private class Status {
- Element element;
- String name;
- ErrorType errorType;
+ private Element element;
+ private String name;
+ private ErrorType errorType;
public Status(String name, Element element, ErrorType errorType) {
this.name = name;
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/AppenderRefPlugin.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/AppenderRefPlugin.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/AppenderRefPlugin.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/AppenderRefPlugin.java Wed Dec 28 07:50:16 2011
@@ -20,18 +20,26 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.status.StatusLogger;
/**
- *
+ * An Appender reference.
*/
@Plugin(name = "appender-ref", type = "Core", printObject = true)
-public class AppenderRefPlugin {
+public final class AppenderRefPlugin {
- protected final static Logger logger = StatusLogger.getLogger();
+ private static final Logger LOGGER = StatusLogger.getLogger();
+ private AppenderRefPlugin() {
+ }
+
+ /**
+ * Create an Appender reference.
+ * @param ref The name of the Appender.
+ * @return The name of the Appender.
+ */
@PluginFactory
public static String createAppenderRef(@PluginAttr("ref") String ref) {
if (ref == null) {
- logger.error("Appender references must contain a reference");
+ LOGGER.error("Appender references must contain a reference");
}
return ref;
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/AppendersPlugin.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/AppendersPlugin.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/AppendersPlugin.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/AppendersPlugin.java Wed Dec 28 07:50:16 2011
@@ -22,11 +22,19 @@ import java.util.concurrent.ConcurrentHa
import java.util.concurrent.ConcurrentMap;
/**
- *
+ * An Appender container.
*/
@Plugin(name = "appenders", type = "Core")
-public class AppendersPlugin {
+public final class AppendersPlugin {
+ private AppendersPlugin() {
+ }
+
+ /**
+ * Create a Map of the Appenders.
+ * @param appenders An array of Appenders.
+ * @return The Appender Map.
+ */
@PluginFactory
public static ConcurrentMap<String, Appender> createAppenders(@PluginElement("appenders") Appender[] appenders) {
ConcurrentMap<String, Appender> map = new ConcurrentHashMap<String, Appender>();
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/LoggersPlugin.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/LoggersPlugin.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/LoggersPlugin.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/LoggersPlugin.java Wed Dec 28 07:50:16 2011
@@ -23,11 +23,19 @@ import java.util.concurrent.ConcurrentHa
import java.util.concurrent.ConcurrentMap;
/**
- *
+ * Container of Logger objects.
*/
@Plugin(name = "loggers", type = "Core")
-public class LoggersPlugin {
+public final class LoggersPlugin {
+ private LoggersPlugin() {
+ }
+
+ /**
+ * Create a Loggers object to contain all the Loggers.
+ * @param loggers An array of Loggers.
+ * @return A Loggers object.
+ */
@PluginFactory
public static Loggers createLoggers(@PluginElement("loggers") LoggerConfig[] loggers) {
ConcurrentMap<String, LoggerConfig> loggerMap = new ConcurrentHashMap<String, LoggerConfig>();
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/Plugin.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/Plugin.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/Plugin.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/Plugin.java Wed Dec 28 07:50:16 2011
@@ -22,17 +22,19 @@ import java.lang.annotation.RetentionPol
import java.lang.annotation.Target;
/**
- *
+ * Annotation that identifies a Class as a Plugin.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Plugin {
+ /**
+ * Value of the elementType when none is specified.
+ */
+ String EMPTY = "";
- public String name();
- public String type();
- public String elementType() default NULL;
- public boolean printObject() default false;
- public boolean deferChildren() default false;
-
- public static final String NULL = "";
+ String name();
+ String type();
+ String elementType() default EMPTY;
+ boolean printObject() default false;
+ boolean deferChildren() default false;
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAttr.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAttr.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAttr.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAttr.java Wed Dec 28 07:50:16 2011
@@ -22,11 +22,11 @@ import java.lang.annotation.RetentionPol
import java.lang.annotation.Target;
/**
- *
+ * Identifies a Plugin Attribute.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface PluginAttr {
- public String value();
+ String value();
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginConfiguration.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginConfiguration.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginConfiguration.java Wed Dec 28 07:50:16 2011
@@ -22,7 +22,7 @@ import java.lang.annotation.RetentionPol
import java.lang.annotation.Target;
/**
- *
+ * Identifies a parameter as a Configuration.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginElement.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginElement.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginElement.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginElement.java Wed Dec 28 07:50:16 2011
@@ -22,11 +22,11 @@ import java.lang.annotation.RetentionPol
import java.lang.annotation.Target;
/**
- *
+ * Identifies a parameter as an element.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface PluginElement {
- public String value();
+ String value();
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginFactory.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginFactory.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginFactory.java Wed Dec 28 07:50:16 2011
@@ -22,7 +22,7 @@ import java.lang.annotation.RetentionPol
import java.lang.annotation.Target;
/**
- *
+ * Identifies a Method as the factory to create the plugin.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java Wed Dec 28 07:50:16 2011
@@ -38,7 +38,7 @@ import java.util.concurrent.CopyOnWriteA
*/
public class PluginManager {
- private static long NANOS_PER_SECOND = 1000000000L;
+ private static final long NANOS_PER_SECOND = 1000000000L;
private static ConcurrentMap<String, ConcurrentMap<String, PluginType>> pluginTypeMap =
new ConcurrentHashMap<String, ConcurrentMap<String, PluginType>>();
@@ -48,12 +48,32 @@ public class PluginManager {
private static final String FILENAME = "Log4j2Plugins.dat";
private static final String LOG4J_PACKAGES = "org.apache.logging.log4j.core";
- private static Logger LOGGER = StatusLogger.getLogger();
+ private static final Logger LOGGER = StatusLogger.getLogger();
+
+ private static String rootDir;
private Map<String, PluginType> plugins = new HashMap<String, PluginType>();
private final String type;
private final Class clazz;
- private static String rootDir;
+
+ /**
+ * Constructor that takes only a type name.
+ * @param type The type name.
+ */
+ public PluginManager(String type) {
+ this.type = type;
+ this.clazz = null;
+ }
+
+ /**
+ * Constructor that takes a type name and a Class.
+ * @param type The type that must be matched.
+ * @param clazz The Class each match must be an instance of.
+ */
+ public PluginManager(String type, Class clazz) {
+ this.type = type;
+ this.clazz = clazz;
+ }
public static void main(String[] args) throws Exception {
if (args == null || args.length < 1) {
@@ -67,34 +87,42 @@ public class PluginManager {
encode(pluginTypeMap);
}
- public PluginManager(String type) {
- this.type = type;
- this.clazz = null;
- }
-
-
- public PluginManager(String type, Class clazz) {
- this.type = type;
- this.clazz = clazz;
- }
-
+ /**
+ * Adds a package name to be scanned for plugins. Must be invoked prior to plugins being collected.
+ * @param p The package name.
+ */
public static void addPackage(String p) {
packages.addIfAbsent(p);
}
+ /**
+ * Returns the type of a specified plugin.
+ * @param name The name of the plugin.
+ * @return The plugin's type.
+ */
public PluginType getPluginType(String name) {
return plugins.get(name.toLowerCase());
}
+ /**
+ * Returns all the matching plugins.
+ * @return A Map containing the name of the plugin and its type.
+ */
public Map<String, PluginType> getPlugins() {
return plugins;
}
+ /**
+ * Locates all the plugins.
+ */
public void collectPlugins() {
collectPlugins(true);
}
-
+ /**
+ * Collects plugins, optionally obtaining them from a preload map.
+ * @param preLoad if true, plugins will be obtained from the preload map.
+ */
public void collectPlugins(boolean preLoad) {
if (pluginTypeMap.containsKey(type)) {
plugins = pluginTypeMap.get(type);
@@ -108,7 +136,7 @@ public class PluginManager {
}
if (preLoad) {
ConcurrentMap<String, ConcurrentMap<String, PluginType>> map = decode(loader);
- if (map != null){
+ if (map != null) {
pluginTypeMap = map;
plugins = map.get(type);
} else {
@@ -122,15 +150,14 @@ public class PluginManager {
for (String pkg : packages) {
r.findInPackage(test, pkg);
}
- for (Class<?> item : r.getClasses())
- {
+ for (Class<?> item : r.getClasses()) {
Plugin p = item.getAnnotation(Plugin.class);
String pluginType = p.type();
if (!pluginTypeMap.containsKey(pluginType)) {
pluginTypeMap.putIfAbsent(pluginType, new ConcurrentHashMap<String, PluginType>());
}
Map<String, PluginType> map = pluginTypeMap.get(pluginType);
- String type = p.elementType().equals(Plugin.NULL) ? p.name() : p.elementType();
+ String type = p.elementType().equals(Plugin.EMPTY) ? p.name() : p.elementType();
map.put(p.name().toLowerCase(), new PluginType(item, type, p.printObject(), p.deferChildren()));
}
long elapsed = System.nanoTime() - start;
@@ -155,11 +182,11 @@ public class PluginManager {
int count = dis.readInt();
ConcurrentMap<String, ConcurrentMap<String, PluginType>> map =
new ConcurrentHashMap<String, ConcurrentMap<String, PluginType>>(count);
- for (int j=0; j < count; ++j) {
+ for (int j = 0; j < count; ++j) {
String type = dis.readUTF();
int entries = dis.readInt();
ConcurrentMap<String, PluginType> types = new ConcurrentHashMap<String, PluginType>(count);
- for (int i=0; i < entries; ++i) {
+ for (int i = 0; i < entries; ++i) {
String key = dis.readUTF();
String className = dis.readUTF();
String name = dis.readUTF();
@@ -210,18 +237,26 @@ public class PluginManager {
public static class PluginTest extends ResolverUtil.ClassTest {
private final Class isA;
- /** Constructs an AnnotatedWith test for the specified annotation type. */
+ /**
+ * Constructs an AnnotatedWith test for the specified annotation type.
+ * @param isA The class to compare against.
+ */
public PluginTest(Class isA) {
this.isA = isA;
}
- /** Returns true if the type is annotated with the class provided to the constructor. */
+ /**
+ * Returns true if the type is annotated with the class provided to the constructor.
+ * @param type The type to check for.
+ * @return true if the Class is of the specified type.
+ */
public boolean matches(Class type) {
return type != null && type.isAnnotationPresent(Plugin.class) &&
(isA == null || isA.isAssignableFrom(type));
}
- @Override public String toString() {
+ @Override
+ public String toString() {
StringBuilder msg = new StringBuilder("annotated with @" + Plugin.class.getSimpleName());
if (isA != null) {
msg.append(" is assignable to " + isA.getSimpleName());
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginValue.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginValue.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginValue.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginValue.java Wed Dec 28 07:50:16 2011
@@ -22,11 +22,11 @@ import java.lang.annotation.RetentionPol
import java.lang.annotation.Target;
/**
- *
+ * Identifies a parameter as a value.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface PluginValue {
- public String value();
+ String value();
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/ResolverUtil.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/ResolverUtil.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/ResolverUtil.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/ResolverUtil.java Wed Dec 28 07:50:16 2011
@@ -64,127 +64,12 @@ import java.util.jar.JarInputStream;
* </p>
*
* @author Tim Fennell
+ * @param <T> The type of the Class that can be returned.
*/
public class ResolverUtil<T> {
/** An instance of Log to use for logging in this class. */
private static final Logger LOG = StatusLogger.getLogger();
- /**
- * A simple interface that specifies how to test classes to determine if they
- * are to be included in the results produced by the ResolverUtil.
- */
- public static interface Test {
- /**
- * Will be called repeatedly with candidate classes. Must return True if a class
- * is to be included in the results, false otherwise.
- */
- boolean matches(Class type);
-
- boolean matches(URI resource);
-
- boolean doesMatchClass();
- boolean doesMatchResource();
- }
-
- public static abstract class ClassTest implements Test {
- public boolean matches(URI resource) {
- throw new UnsupportedOperationException();
- }
-
- public boolean doesMatchClass() {
- return true;
- }
- public boolean doesMatchResource() {
- return false;
- }
- }
-
- public static abstract class ResourceTest implements Test {
- public boolean matches(Class cls) {
- throw new UnsupportedOperationException();
- }
-
- public boolean doesMatchClass() {
- return false;
- }
- public boolean doesMatchResource() {
- return true;
- }
- }
-
- /**
- * A Test that checks to see if each class is assignable to the provided class. Note
- * that this test will match the parent type itself if it is presented for matching.
- */
- public static class IsA extends ClassTest {
- private Class parent;
-
- /** Constructs an IsA test using the supplied Class as the parent class/interface. */
- public IsA(Class parentType) { this.parent = parentType; }
-
- /** Returns true if type is assignable to the parent type supplied in the constructor. */
- public boolean matches(Class type) {
- return type != null && parent.isAssignableFrom(type);
- }
-
- @Override public String toString() {
- return "is assignable to " + parent.getSimpleName();
- }
- }
-
- /**
- * A Test that checks to see if each class name ends with the provided suffix.
- */
- public static class NameEndsWith extends ClassTest {
- private String suffix;
-
- /** Constructs a NameEndsWith test using the supplied suffix. */
- public NameEndsWith(String suffix) { this.suffix = suffix; }
-
- /** Returns true if type name ends with the suffix supplied in the constructor. */
- public boolean matches(Class type) {
- return type != null && type.getName().endsWith(suffix);
- }
-
- @Override public String toString() {
- return "ends with the suffix " + suffix;
- }
- }
-
- /**
- * A Test that checks to see if each class is annotated with a specific annotation. If it
- * is, then the test returns true, otherwise false.
- */
- public static class AnnotatedWith extends ClassTest {
- private Class<? extends Annotation> annotation;
-
- /** Constructs an AnnotatedWith test for the specified annotation type. */
- public AnnotatedWith(Class<? extends Annotation> annotation) { this.annotation = annotation; }
-
- /** Returns true if the type is annotated with the class provided to the constructor. */
- public boolean matches(Class type) {
- return type != null && type.isAnnotationPresent(annotation);
- }
-
- @Override public String toString() {
- return "annotated with @" + annotation.getSimpleName();
- }
- }
-
- public static class NameIs extends ResourceTest {
- private String name;
-
- public NameIs(String name) { this.name = "/" + name; }
-
- public boolean matches(URI resource) {
- return (resource.getPath().endsWith(name));
- }
-
- @Override public String toString() {
- return "named " + name;
- }
- }
-
/** The set of matches being accumulated. */
private Set<Class<? extends T>> classMatches = new HashSet<Class<?extends T>>();
@@ -207,6 +92,10 @@ public class ResolverUtil<T> {
return classMatches;
}
+ /**
+ * Return the matching resources.
+ * @return A Set of URIs that match the criteria.
+ */
public Set<URI> getResources() {
return resourceMatches;
}
@@ -240,7 +129,9 @@ public class ResolverUtil<T> {
* @param packageNames one or more package names to scan (including subpackages) for classes
*/
public void findImplementations(Class parent, String... packageNames) {
- if (packageNames == null) return;
+ if (packageNames == null) {
+ return;
+ }
Test test = new IsA(parent);
for (String pkg : packageNames) {
@@ -256,7 +147,9 @@ public class ResolverUtil<T> {
* @param packageNames one or more package names to scan (including subpackages) for classes
*/
public void findSuffix(String suffix, String... packageNames) {
- if (packageNames == null) return;
+ if (packageNames == null) {
+ return;
+ }
Test test = new NameEndsWith(suffix);
for (String pkg : packageNames) {
@@ -272,7 +165,9 @@ public class ResolverUtil<T> {
* @param packageNames one or more package names to scan (including subpackages) for classes
*/
public void findAnnotated(Class<? extends Annotation> annotation, String... packageNames) {
- if (packageNames == null) return;
+ if (packageNames == null) {
+ return;
+ }
Test test = new AnnotatedWith(annotation);
for (String pkg : packageNames) {
@@ -281,7 +176,9 @@ public class ResolverUtil<T> {
}
public void findNamedResource(String name, String... pathNames) {
- if (pathNames == null) return;
+ if (pathNames == null) {
+ return;
+ }
Test test = new NameIs(name);
for (String pkg : pathNames) {
@@ -297,7 +194,9 @@ public class ResolverUtil<T> {
* @param packageNames one or more package names to scan (including subpackages) for classes
*/
public void find(Test test, String... packageNames) {
- if (packageNames == null) return;
+ if (packageNames == null) {
+ return;
+ }
for (String pkg : packageNames) {
findInPackage(test, pkg);
@@ -321,8 +220,7 @@ public class ResolverUtil<T> {
try {
urls = loader.getResources(packageName);
- }
- catch (IOException ioe) {
+ } catch (IOException ioe) {
LOG.warn("Could not read package: " + packageName, ioe);
return;
}
@@ -333,7 +231,7 @@ public class ResolverUtil<T> {
urlPath = URLDecoder.decode(urlPath, "UTF-8");
// If it's a file in a directory, trim the stupid file: spec
- if ( urlPath.startsWith("file:") ) {
+ if (urlPath.startsWith("file:")) {
urlPath = urlPath.substring(5);
}
@@ -344,14 +242,12 @@ public class ResolverUtil<T> {
LOG.info("Scanning for classes in [" + urlPath + "] matching criteria: " + test);
File file = new File(urlPath);
- if ( file.isDirectory() ) {
+ if (file.isDirectory()) {
loadImplementationsInDirectory(test, packageName, file);
- }
- else {
+ } else {
loadImplementationsInJar(test, packageName, file);
}
- }
- catch (IOException ioe) {
+ } catch (IOException ioe) {
LOG.warn("could not read entries", ioe);
}
}
@@ -375,14 +271,13 @@ public class ResolverUtil<T> {
StringBuilder builder;
for (File file : files) {
- builder = new StringBuilder(100);
+ builder = new StringBuilder();
builder.append(parent).append("/").append(file.getName());
- String packageOrClass = ( parent == null ? file.getName() : builder.toString() );
+ String packageOrClass = parent == null ? file.getName() : builder.toString();
if (file.isDirectory()) {
loadImplementationsInDirectory(test, packageOrClass, file);
- }
- else if (isTestApplicable(test, file.getName())) {
+ } else if (isTestApplicable(test, file.getName())) {
addIfMatching(test, packageOrClass);
}
}
@@ -407,14 +302,13 @@ public class ResolverUtil<T> {
JarEntry entry;
JarInputStream jarStream = new JarInputStream(new FileInputStream(jarfile));
- while ( (entry = jarStream.getNextJarEntry() ) != null) {
+ while ((entry = jarStream.getNextJarEntry()) != null) {
String name = entry.getName();
if (!entry.isDirectory() && name.startsWith(parent) && isTestApplicable(test, name)) {
addIfMatching(test, name);
}
}
- }
- catch (IOException ioe) {
+ } catch (IOException ioe) {
LOG.error("Could not search jar file '" + jarfile + "' for classes matching criteria: " +
test + " due to an IOException", ioe);
}
@@ -437,8 +331,8 @@ public class ResolverUtil<T> {
}
Class type = loader.loadClass(externalName);
- if (test.matches(type) ) {
- classMatches.add( (Class<T>) type);
+ if (test.matches(type)) {
+ classMatches.add((Class<T>) type);
}
}
if (test.doesMatchResource()) {
@@ -450,10 +344,167 @@ public class ResolverUtil<T> {
resourceMatches.add(url.toURI());
}
}
- }
- catch (Throwable t) {
+ } catch (Throwable t) {
LOG.warn("Could not examine class '" + fqn + "' due to a " +
t.getClass().getName() + " with message: " + t.getMessage());
}
}
-}
\ No newline at end of file
+
+ /**
+ * A simple interface that specifies how to test classes to determine if they
+ * are to be included in the results produced by the ResolverUtil.
+ */
+ public interface Test {
+ /**
+ * Will be called repeatedly with candidate classes. Must return True if a class
+ * is to be included in the results, false otherwise.
+ * @param type The Class to match against.
+ * @return true if the Class matches.
+ */
+ boolean matches(Class type);
+
+ /**
+ * Test for a resource.
+ * @param resource The URI to the resource.
+ * @return true if the resource matches.
+ */
+ boolean matches(URI resource);
+
+ boolean doesMatchClass();
+ boolean doesMatchResource();
+ }
+
+ /**
+ * Test against a Class.
+ */
+ public abstract static class ClassTest implements Test {
+ public boolean matches(URI resource) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean doesMatchClass() {
+ return true;
+ }
+ public boolean doesMatchResource() {
+ return false;
+ }
+ }
+
+ /**
+ * Test against a resource.
+ */
+ public abstract static class ResourceTest implements Test {
+ public boolean matches(Class cls) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean doesMatchClass() {
+ return false;
+ }
+ public boolean doesMatchResource() {
+ return true;
+ }
+ }
+
+ /**
+ * A Test that checks to see if each class is assignable to the provided class. Note
+ * that this test will match the parent type itself if it is presented for matching.
+ */
+ public static class IsA extends ClassTest {
+ private Class parent;
+
+ /**
+ * Constructs an IsA test using the supplied Class as the parent class/interface.
+ * @param parentType The parent class to check for.
+ */
+ public IsA(Class parentType) { this.parent = parentType; }
+
+ /**
+ * Returns true if type is assignable to the parent type supplied in the constructor.
+ * @param type The Class to check.
+ * @return true if the Class matches.
+ */
+ public boolean matches(Class type) {
+ return type != null && parent.isAssignableFrom(type);
+ }
+
+ @Override
+ public String toString() {
+ return "is assignable to " + parent.getSimpleName();
+ }
+ }
+
+ /**
+ * A Test that checks to see if each class name ends with the provided suffix.
+ */
+ public static class NameEndsWith extends ClassTest {
+ private String suffix;
+
+ /**
+ * Constructs a NameEndsWith test using the supplied suffix.
+ * @param suffix the String suffix to check for.
+ */
+ public NameEndsWith(String suffix) { this.suffix = suffix; }
+
+ /**
+ * Returns true if type name ends with the suffix supplied in the constructor.
+ * @param type The Class to check.
+ * @return true if the Class matches.
+ */
+ public boolean matches(Class type) {
+ return type != null && type.getName().endsWith(suffix);
+ }
+
+ @Override
+ public String toString() {
+ return "ends with the suffix " + suffix;
+ }
+ }
+
+ /**
+ * A Test that checks to see if each class is annotated with a specific annotation. If it
+ * is, then the test returns true, otherwise false.
+ */
+ public static class AnnotatedWith extends ClassTest {
+ private Class<? extends Annotation> annotation;
+
+ /**
+ * Constructs an AnnotatedWith test for the specified annotation type.
+ * @param annotation The annotation to check for.
+ */
+ public AnnotatedWith(Class<? extends Annotation> annotation) {
+ this.annotation = annotation;
+ }
+
+ /**
+ * Returns true if the type is annotated with the class provided to the constructor.
+ * @param type the Class to match against.
+ * @return true if the Classes match.
+ */
+ public boolean matches(Class type) {
+ return type != null && type.isAnnotationPresent(annotation);
+ }
+
+ @Override
+ public String toString() {
+ return "annotated with @" + annotation.getSimpleName();
+ }
+ }
+
+ /**
+ * A Test that checks to see if the class name matches.
+ */
+ public static class NameIs extends ResourceTest {
+ private String name;
+
+ public NameIs(String name) { this.name = "/" + name; }
+
+ public boolean matches(URI resource) {
+ return (resource.getPath().endsWith(name));
+ }
+
+ @Override public String toString() {
+ return "named " + name;
+ }
+ }
+}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/BurstFilter.java Wed Dec 28 07:50:16 2011
@@ -1,21 +1,19 @@
-/* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. 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
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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
+ * 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. See the License for the
- * specific language governing permissions and limitations
- * under the License.
+ * 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.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
*/
-
package org.apache.logging.log4j.core.filter;
import org.apache.logging.log4j.Level;
@@ -55,7 +53,7 @@ import java.util.concurrent.TimeUnit;
*/
@Plugin(name = "BurstFilter", type = "Core", elementType = "filter", printObject = true)
-public class BurstFilter extends FilterBase {
+public final class BurstFilter extends FilterBase {
private static final long NANOS_IN_SECONDS = 1000000000;
@@ -211,7 +209,7 @@ public class BurstFilter extends FilterB
* average rate. The default is 10 times the rate.
* @param match The Result to return when the filter matches. Defaults to Result.NEUTRAL.
* @param mismatch The Result to return when the filter does not match. The default is Result.DENY.
- * @return
+ * @return A BurstFilter.
*/
@PluginFactory
public static BurstFilter createFilter(@PluginAttr("level") String level,
@@ -235,4 +233,4 @@ public class BurstFilter extends FilterB
}
return new BurstFilter(lvl, eventRate, max, onMatch, onMismatch);
}
-}
\ No newline at end of file
+}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/FilterBase.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/FilterBase.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/FilterBase.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/FilterBase.java Wed Dec 28 07:50:16 2011
@@ -32,59 +32,91 @@ import org.apache.logging.log4j.message.
*
*/
public abstract class FilterBase implements Filter, Lifecycle {
+ /**
+ * Allow subclasses access to the status logger without creating another instance.
+ */
+ protected static final org.apache.logging.log4j.Logger LOGGER = StatusLogger.getLogger();
- protected boolean started;
-
+ /**
+ * The onMatch Result.
+ */
protected final Result onMatch;
+ /**
+ * The onMismatch Result.
+ */
protected final Result onMismatch;
- protected static final org.apache.logging.log4j.Logger logger = StatusLogger.getLogger();
-
- protected static final String ON_MATCH = "onmatch";
- protected static final String ON_MISMATCH = "onmismatch";
+ private boolean started;
+ /**
+ * The default constructor.
+ */
protected FilterBase() {
this(null, null);
}
+ /**
+ * Constructor that allows the onMatch and onMismatch actions to be set.
+ * @param onMatch The result to return when a match occurs.
+ * @param onMismatch The result to return when a match dos not occur.
+ */
protected FilterBase(Result onMatch, Result onMismatch) {
this.onMatch = onMatch == null ? Result.NEUTRAL : onMatch;
this.onMismatch = onMismatch == null ? Result.DENY : onMismatch;
}
+ /**
+ * Mark the Filter as started.
+ */
public void start() {
started = true;
}
+ /**
+ * Determine if the the Filter has started.
+ * @return true if the Filter is started, false otherwise.
+ */
public boolean isStarted() {
return started;
}
+ /**
+ * Mark the Filter as stopped.
+ */
public void stop() {
started = false;
}
+ /**
+ * Return the Result to be returned when a match does not occur.
+ * @return the onMismatch Result.
+ */
public final Result getOnMismatch() {
return onMismatch;
}
+ /**
+ * Return the Result to be returned when a match occurs.
+ * @return the onMatch Result.
+ */
public final Result getOnMatch() {
return onMatch;
}
+ @Override
public String toString() {
return this.getClass().getSimpleName();
}
/**
* Appender Filter method. The default returns NEUTRAL.
- * @param logger the logger
- * @param level
- * @param marker
- * @param msg
- * @param params
- * @return
+ * @param logger the Logger.
+ * @param level The logging Level.
+ * @param marker The Marker, if any.
+ * @param msg The message, if present.
+ * @param params An array of parameters or null.
+ * @return The Result of filtering.
*/
public Result filter(Logger logger, Level level, Marker marker, String msg, Object[] params) {
return Result.NEUTRAL;
@@ -92,12 +124,12 @@ public abstract class FilterBase impleme
/**
* Appender Filter method. The default returns NEUTRAL.
- * @param logger
- * @param level
- * @param marker
- * @param msg
- * @param t
- * @return
+ * @param logger the Logger.
+ * @param level The logging Level.
+ * @param marker The Marker, if any.
+ * @param msg The message, if present.
+ * @param t A throwable or null.
+ * @return The Result of filtering.
*/
public Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t) {
return Result.NEUTRAL;
@@ -105,12 +137,12 @@ public abstract class FilterBase impleme
/**
* Appender Filter method. The default returns NEUTRAL.
- * @param logger
- * @param level
- * @param marker
- * @param msg
- * @param t
- * @return
+ * @param logger the Logger.
+ * @param level The logging Level.
+ * @param marker The Marker, if any.
+ * @param msg The message, if present.
+ * @param t A throwable or null.
+ * @return The Result of filtering.
*/
public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) {
return Result.NEUTRAL;
@@ -118,8 +150,8 @@ public abstract class FilterBase impleme
/**
* Context Filter method. The default returns NEUTRAL.
- * @param event
- * @return
+ * @param event The LogEvent.
+ * @return The Result of filtering.
*/
public Result filter(LogEvent event) {
return Result.NEUTRAL;
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/Filterable.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/Filterable.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/Filterable.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/Filterable.java Wed Dec 28 07:50:16 2011
@@ -23,7 +23,7 @@ import org.apache.logging.log4j.core.Log
import java.util.Iterator;
/**
- *
+ * Enhances a Class by allowing it to contain Filters.
*/
public class Filterable implements Filtering {
@@ -37,13 +37,17 @@ public class Filterable implements Filte
}
/**
- * Return the Filter
+ * Return the Filter.
* @return the Filter.
*/
public Filter getFilter() {
return filter;
}
+ /**
+ * Add a filter.
+ * @param filter The Filter to add.
+ */
public synchronized void addFilter(Filter filter) {
if (this.filter == null) {
this.filter = filter;
@@ -55,6 +59,10 @@ public class Filterable implements Filte
}
}
+ /**
+ * Remove a Filter.
+ * @param filter The Filter to remove.
+ */
public synchronized void removeFilter(Filter filter) {
if (this.filter == filter) {
this.filter = null;
@@ -72,22 +80,37 @@ public class Filterable implements Filte
}
}
+ /**
+ * Determines if a Filter is present.
+ * @return false if no Filter is present.
+ */
public boolean hasFilter() {
return filter != null;
}
+ /**
+ * Make the Filter available for use.
+ */
public void startFilter() {
if (filter != null && filter instanceof Lifecycle) {
((Lifecycle) filter).start();
}
}
+ /**
+ * Cleanup the Filter.
+ */
public void stopFilter() {
if (filter != null && filter instanceof Lifecycle) {
((Lifecycle) filter).stop();
}
}
+ /**
+ * Determine if the LogEvent should be processed or ignored.
+ * @param event The LogEvent.
+ * @return true if the LogEvent should be processed.
+ */
public boolean isFiltered(LogEvent event) {
return filter != null && filter.filter(event) == Filter.Result.DENY;
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java Wed Dec 28 07:50:16 2011
@@ -51,7 +51,7 @@ public class MapFilter extends FilterBas
@Override
public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) {
if (msg instanceof MapMessage) {
- return filter((MapMessage)msg);
+ return filter((MapMessage) msg);
}
return Result.NEUTRAL;
}
@@ -109,25 +109,25 @@ public class MapFilter extends FilterBas
@PluginAttr("onmatch") String match,
@PluginAttr("onmismatch") String mismatch) {
if (pairs == null || pairs.length == 0) {
- logger.error("keys and values must be specified for the MapFilter");
+ LOGGER.error("keys and values must be specified for the MapFilter");
return null;
}
Map<String, String> map = new HashMap<String, String>();
for (KeyValuePair pair : pairs) {
String key = pair.getKey();
if (key == null) {
- logger.error("A null key is not valid in MapFilter");
+ LOGGER.error("A null key is not valid in MapFilter");
continue;
}
String value = pair.getValue();
if (value == null) {
- logger.error("A null value for key " + key + " is not allowed in MapFilter");
+ LOGGER.error("A null value for key " + key + " is not allowed in MapFilter");
continue;
}
map.put(pair.getKey(), pair.getValue());
}
if (map.size() == 0) {
- logger.error("MapFilter is not configured with any valid key value pairs");
+ LOGGER.error("MapFilter is not configured with any valid key value pairs");
return null;
}
boolean isAnd = oper == null || !oper.equalsIgnoreCase("or");
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java?rev=1225138&r1=1225137&r2=1225138&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java Wed Dec 28 07:50:16 2011
@@ -80,7 +80,7 @@ public final class MarkerFilter extends
@PluginAttr("onMismatch") String mismatch) {
if (marker == null) {
- logger.error("A marker must be provided for MarkerFilter");
+ LOGGER.error("A marker must be provided for MarkerFilter");
return null;
}
Marker m = MarkerManager.getMarker(marker);