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 2015/09/27 20:41:36 UTC
[44/50] [abbrv] logging-log4j2 git commit: Checkstyle
Checkstyle
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/8606650e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/8606650e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/8606650e
Branch: refs/heads/LOG4J2-1136
Commit: 8606650ec11ec6abfe287546576509856c9aeefe
Parents: 37c992b
Author: rpopma <rp...@apache.org>
Authored: Thu Sep 24 16:43:46 2015 +0200
Committer: Ralph Goers <rg...@nextiva.com>
Committed: Sun Sep 27 10:49:28 2015 -0700
----------------------------------------------------------------------
.../logging/log4j/core/async/AsyncLogger.java | 20 +-
.../log4j/core/async/AsyncLoggerConfig.java | 1 +
.../core/async/AsyncLoggerConfigHelper.java | 4 +-
.../log4j/core/async/DaemonThreadFactory.java | 6 +-
.../core/config/AbstractConfiguration.java | 196 ++++++++++---------
.../log4j/core/config/AppenderControl.java | 16 +-
.../AwaitCompletionReliabilityStrategy.java | 35 +++-
...AwaitUnconditionallyReliabilityStrategy.java | 10 +-
.../core/config/LockingReliabilityStrategy.java | 35 +++-
.../log4j/core/config/NullConfiguration.java | 5 +-
.../log4j/core/config/ReliabilityStrategy.java | 15 +-
.../core/config/ReliabilityStrategyFactory.java | 2 +-
12 files changed, 205 insertions(+), 140 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8606650e/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
index d775731..032ecd1 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
@@ -113,7 +113,7 @@ public class AsyncLogger extends Logger {
private static final Clock CLOCK = ClockFactory.getClock();
private static volatile NanoClock nanoClock = new DummyNanoClock();
- private static final ExecutorService executor = Executors.newSingleThreadExecutor(new DaemonThreadFactory(
+ private static final ExecutorService EXECUTOR = Executors.newSingleThreadExecutor(new DaemonThreadFactory(
"AsyncLogger-"));
static {
@@ -122,7 +122,7 @@ public class AsyncLogger extends Logger {
final int ringBufferSize = calculateRingBufferSize();
final WaitStrategy waitStrategy = createWaitStrategy();
- disruptor = new Disruptor<>(RingBufferLogEvent.FACTORY, ringBufferSize, executor, ProducerType.MULTI,
+ disruptor = new Disruptor<>(RingBufferLogEvent.FACTORY, ringBufferSize, EXECUTOR, ProducerType.MULTI,
waitStrategy);
disruptor.handleExceptionsWith(getExceptionHandler());
disruptor.handleEventsWith(new RingBufferLogEventHandler());
@@ -168,13 +168,13 @@ public class AsyncLogger extends Logger {
* deadlock when the RingBuffer is full. (LOG4J2-471)
*/
private static void initInfoForExecutorThread() {
- executor.submit(new Runnable() {
+ EXECUTOR.submit(new Runnable() {
@Override
public void run() {
final boolean isAppenderThread = true;
final Info info = new Info(new RingBufferLogEventTranslator(), //
Thread.currentThread().getName(), isAppenderThread);
- Info.threadlocalInfo.set(info);
+ Info.THREADLOCAL.set(info);
}
});
}
@@ -215,7 +215,7 @@ public class AsyncLogger extends Logger {
* Tuple with the event translator and thread name for a thread.
*/
static class Info {
- private static final ThreadLocal<Info> threadlocalInfo = new ThreadLocal<Info>() {
+ private static final ThreadLocal<Info> THREADLOCAL = new ThreadLocal<Info>() {
@Override
protected Info initialValue() {
// by default, set isAppenderThread to false
@@ -226,7 +226,8 @@ public class AsyncLogger extends Logger {
private final String cachedThreadName;
private final boolean isAppenderThread;
- public Info(final RingBufferLogEventTranslator translator, final String threadName, final boolean appenderThread) {
+ public Info(final RingBufferLogEventTranslator translator, final String threadName,
+ final boolean appenderThread) {
this.translator = translator;
this.cachedThreadName = threadName;
this.isAppenderThread = appenderThread;
@@ -252,7 +253,7 @@ public class AsyncLogger extends Logger {
private void logMessage0(final Disruptor<RingBufferLogEvent> theDisruptor, final String fqcn, final Level level,
final Marker marker, final Message message, final Throwable thrown) {
- final Info info = Info.threadlocalInfo.get();
+ final Info info = Info.THREADLOCAL.get();
logMessageInAppropriateThread(info, theDisruptor, fqcn, level, marker, message, thrown);
}
@@ -404,8 +405,8 @@ public class AsyncLogger extends Logger {
}
}
temp.shutdown(); // busy-spins until all events currently in the disruptor have been processed
- executor.shutdown(); // finally, kill the processor thread
- Info.threadlocalInfo.remove(); // LOG4J2-323
+ EXECUTOR.shutdown(); // finally, kill the processor thread
+ Info.THREADLOCAL.remove(); // LOG4J2-323
}
/**
@@ -420,6 +421,7 @@ public class AsyncLogger extends Logger {
* Creates and returns a new {@code RingBufferAdmin} that instruments the ringbuffer of the {@code AsyncLogger}.
*
* @param contextName name of the global {@code AsyncLoggerContext}
+ * @return a new {@code RingBufferAdmin} that instruments the ringbuffer
*/
public static RingBufferAdmin createRingBufferAdmin(final String contextName) {
return RingBufferAdmin.forAsyncLogger(disruptor.getRingBuffer(), contextName);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8606650e/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
index 1324cbb..186575d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
@@ -150,6 +150,7 @@ public class AsyncLoggerConfig extends LoggerConfig {
* ringbuffer of this {@code AsyncLoggerConfig}.
*
* @param contextName name of the {@code LoggerContext}
+ * @return a new {@code RingBufferAdmin} that instruments the ringbuffer
*/
public RingBufferAdmin createRingBufferAdmin(final String contextName) {
return helper.createRingBufferAdmin(contextName, getName());
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8606650e/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java
index 955e7f6..9a71899 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java
@@ -273,8 +273,8 @@ class AsyncLoggerConfigHelper {
/**
* Returns {@code true} if the specified disruptor still has unprocessed events.
*/
- private static boolean hasBacklog(final Disruptor<?> disruptor) {
- final RingBuffer<?> ringBuffer = disruptor.getRingBuffer();
+ private static boolean hasBacklog(final Disruptor<?> theDisruptor) {
+ final RingBuffer<?> ringBuffer = theDisruptor.getRingBuffer();
return !ringBuffer.hasAvailableCapacity(ringBuffer.getBufferSize());
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8606650e/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
index 8187e6f..127ec75 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
@@ -24,9 +24,9 @@ import java.util.concurrent.atomic.AtomicInteger;
*/
public class DaemonThreadFactory implements ThreadFactory {
- final ThreadGroup group;
- final AtomicInteger threadNumber = new AtomicInteger(1);
- final String threadNamePrefix;
+ private final ThreadGroup group;
+ private final AtomicInteger threadNumber = new AtomicInteger(1);
+ private final String threadNamePrefix;
public DaemonThreadFactory(final String threadNamePrefix) {
this.threadNamePrefix = threadNamePrefix;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8606650e/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
index 9a36314..c1a3b46 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
@@ -87,16 +87,26 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
protected ConfigurationMonitor monitor = new DefaultConfigurationMonitor();
/**
- * The Advertiser which exposes appender configurations to external systems.
+ * Packages found in configuration "packages" attribute.
*/
- private Advertiser advertiser = new DefaultAdvertiser();
- private Node advertiserNode = null;
- private Object advertisement;
+ protected final List<String> pluginPackages = new ArrayList<>();
+
+ /**
+ * The plugin manager.
+ */
+ protected PluginManager pluginManager;
/**
- *
+ * Shutdown hook is enabled by default.
*/
protected boolean isShutdownHookEnabled = true;
+
+ /**
+ * The Advertiser which exposes appender configurations to external systems.
+ */
+ private Advertiser advertiser = new DefaultAdvertiser();
+ private Node advertiserNode = null;
+ private Object advertisement;
private String name;
private ConcurrentMap<String, Appender> appenders = new ConcurrentHashMap<>();
private ConcurrentMap<String, LoggerConfig> loggers = new ConcurrentHashMap<>();
@@ -106,8 +116,6 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
private final StrSubstitutor subst = new StrSubstitutor(tempLookup);
private LoggerConfig root = new LoggerConfig();
private final ConcurrentMap<String, Object> componentMap = new ConcurrentHashMap<>();
- protected final List<String> pluginPackages = new ArrayList<>();
- protected PluginManager pluginManager;
private final ConfigurationSource configurationSource;
private ScriptManager scriptManager;
@@ -172,7 +180,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
}
/**
- * Start the configuration
+ * Start the configuration.
*/
@Override
public void start() {
@@ -204,7 +212,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
public void stop() {
this.setStopping();
LOGGER.trace("Stopping {}...", this);
-
+
for (final LoggerConfig loggerConfig : loggers.values()) {
loggerConfig.getReliabilityStrategy().beforeStopConfiguration(this);
}
@@ -221,8 +229,8 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
// every time the configuration changes...
//
// Uncomment the line below after LOG4J2-493 is fixed
- //AsyncLogger.stop();
- //LOGGER.trace("AbstractConfiguration stopped AsyncLogger disruptor.");
+ // AsyncLogger.stop();
+ // LOGGER.trace("AbstractConfiguration stopped AsyncLogger disruptor.");
}
}
// similarly, first stop AsyncLoggerConfig Disruptor thread(s)
@@ -311,8 +319,8 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
}
protected Level getDefaultStatus() {
- final String statusLevel = PropertiesUtil.getProperties().getStringProperty(Constants.LOG4J_DEFAULT_STATUS_LEVEL,
- Level.ERROR.name());
+ final String statusLevel = PropertiesUtil.getProperties().getStringProperty(
+ Constants.LOG4J_DEFAULT_STATUS_LEVEL, Level.ERROR.name());
try {
return Level.toLevel(statusLevel);
} catch (final Exception ex) {
@@ -321,7 +329,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
}
protected void createAdvertiser(final String advertiserString, final ConfigurationSource configSource,
- final byte[] buffer, final String contentType) {
+ final byte[] buffer, final String contentType) {
if (advertiserString != null) {
final Node node = new Node(null, advertiserString, null);
final Map<String, String> attributes = node.getAttributes();
@@ -336,12 +344,10 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
}
private void setupAdvertisement() {
- if (advertiserNode != null)
- {
+ if (advertiserNode != null) {
final String name = advertiserNode.getName();
final PluginType<?> type = pluginManager.getPluginType(name);
- if (type != null)
- {
+ if (type != null) {
final Class<? extends Advertiser> clazz = type.getPluginClass().asSubclass(Advertiser.class);
try {
advertiser = clazz.newInstance();
@@ -411,8 +417,8 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
copy.add(child.getObject(CustomLevelConfig.class));
customLevels = copy;
} else {
- LOGGER.error("Unknown object \"{}\" of type {} is ignored.", child.getName(),
- child.getObject().getClass().getName());
+ LOGGER.error("Unknown object \"{}\" of type {} is ignored.", child.getName(), child.getObject()
+ .getClass().getName());
}
}
@@ -447,9 +453,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
// TODO: reduce duplication between this method and DefaultConfiguration constructor
setName(DefaultConfiguration.DEFAULT_NAME);
final Layout<? extends Serializable> layout = PatternLayout.newBuilder()
- .withPattern(DefaultConfiguration.DEFAULT_PATTERN)
- .withConfiguration(this)
- .build();
+ .withPattern(DefaultConfiguration.DEFAULT_PATTERN).withConfiguration(this).build();
final Appender appender = ConsoleAppender.createDefaultAppenderForLayout(layout);
appender.start();
addAppender(appender);
@@ -457,13 +461,14 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
root.addAppender(appender, null, null);
final String levelName = PropertiesUtil.getProperties().getStringProperty(DefaultConfiguration.DEFAULT_LEVEL);
- final Level level = levelName != null && Level.getLevel(levelName) != null ?
- Level.getLevel(levelName) : Level.ERROR;
+ final Level level = levelName != null && Level.getLevel(levelName) != null ? Level.getLevel(levelName)
+ : Level.ERROR;
root.setLevel(level);
}
/**
* Set the name of the configuration.
+ *
* @param name The name.
*/
public void setName(final String name) {
@@ -472,6 +477,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Returns the name of the configuration.
+ *
* @return the name of the configuration.
*/
@Override
@@ -481,6 +487,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Add a listener for changes on the configuration.
+ *
* @param listener The ConfigurationListener to add.
*/
@Override
@@ -490,6 +497,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Remove a ConfigurationListener.
+ *
* @param listener The ConfigurationListener to remove.
*/
@Override
@@ -499,6 +507,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Returns the Appender with the specified name.
+ *
* @param appenderName The name of the Appender.
* @return the Appender with the specified name or null if the Appender cannot be located.
*/
@@ -510,6 +519,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Returns a Map containing all the Appenders and their name.
+ *
* @return A Map containing each Appender's name and the Appender object.
*/
@Override
@@ -519,6 +529,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Adds an Appender to the configuration.
+ *
* @param appender The Appender to add.
*/
@Override
@@ -552,17 +563,17 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
}
/**
- * Associates an Appender with a LoggerConfig. This method is synchronized in case a Logger with the
- * same name is being updated at the same time.
+ * Associates an Appender with a LoggerConfig. This method is synchronized in case a Logger with the same name is
+ * being updated at the same time.
*
- * Note: This method is not used when configuring via configuration. It is primarily used by
- * unit tests.
+ * Note: This method is not used when configuring via configuration. It is primarily used by unit tests.
+ *
* @param logger The Logger the Appender will be associated with.
* @param appender The Appender.
*/
@Override
public synchronized void addLoggerAppender(final org.apache.logging.log4j.core.Logger logger,
- final Appender appender) {
+ final Appender appender) {
final String name = logger.getName();
appenders.putIfAbsent(appender.getName(), appender);
final LoggerConfig lc = getLoggerConfig(name);
@@ -577,12 +588,13 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
logger.getContext().updateLoggers();
}
}
+
/**
- * Associates a Filter with a LoggerConfig. This method is synchronized in case a Logger with the
- * same name is being updated at the same time.
+ * Associates a Filter with a LoggerConfig. This method is synchronized in case a Logger with the same name is being
+ * updated at the same time.
*
- * Note: This method is not used when configuring via configuration. It is primarily used by
- * unit tests.
+ * Note: This method is not used when configuring via configuration. It is primarily used by unit tests.
+ *
* @param logger The Logger the Footer will be associated with.
* @param filter The Filter.
*/
@@ -601,18 +613,18 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
logger.getContext().updateLoggers();
}
}
+
/**
- * Marks a LoggerConfig as additive. This method is synchronized in case a Logger with the
- * same name is being updated at the same time.
+ * Marks a LoggerConfig as additive. This method is synchronized in case a Logger with the same name is being
+ * updated at the same time.
*
- * Note: This method is not used when configuring via configuration. It is primarily used by
- * unit tests.
+ * Note: This method is not used when configuring via configuration. It is primarily used by unit tests.
+ *
* @param logger The Logger the Appender will be associated with.
* @param additive True if the LoggerConfig should be additive, false otherwise.
*/
@Override
- public synchronized void setLoggerAdditive(final org.apache.logging.log4j.core.Logger logger,
- final boolean additive) {
+ public synchronized void setLoggerAdditive(final org.apache.logging.log4j.core.Logger logger, final boolean additive) {
final String loggerName = logger.getName();
final LoggerConfig lc = getLoggerConfig(loggerName);
if (lc.getName().equals(loggerName)) {
@@ -627,9 +639,10 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
}
/**
- * Remove an Appender. First removes any associations between LoggerConfigs and the Appender, removes
- * the Appender from this appender list and then stops the appender. This method is synchronized in
- * case an Appender with the same name is being added during the removal.
+ * Remove an Appender. First removes any associations between LoggerConfigs and the Appender, removes the Appender
+ * from this appender list and then stops the appender. This method is synchronized in case an Appender with the
+ * same name is being added during the removal.
+ *
* @param appenderName the name of the appender to remove.
*/
public synchronized void removeAppender(final String appenderName) {
@@ -645,6 +658,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/*
* (non-Javadoc)
+ *
* @see org.apache.logging.log4j.core.config.Configuration#getCustomLevels()
*/
@Override
@@ -653,8 +667,9 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
}
/**
- * Locates the appropriate LoggerConfig for a Logger name. This will remove tokens from the
- * package name as necessary or return the root LoggerConfig if no other matches were found.
+ * Locates the appropriate LoggerConfig for a Logger name. This will remove tokens from the package name as
+ * necessary or return the root LoggerConfig if no other matches were found.
+ *
* @param loggerName The Logger name.
* @return The located LoggerConfig.
*/
@@ -676,6 +691,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Returns the root Logger.
+ *
* @return the root Logger.
*/
@Override
@@ -685,6 +701,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Returns a Map of all the LoggerConfigs.
+ *
* @return a Map with each entry containing the name of the Logger and the LoggerConfig.
*/
@Override
@@ -694,6 +711,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Returns the LoggerConfig with the specified name.
+ *
* @param loggerName The Logger name.
* @return The LoggerConfig or null if no match was found.
*/
@@ -702,8 +720,8 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
}
/**
- * Add a loggerConfig. The LoggerConfig must already be configured with Appenders, Filters, etc.
- * After addLogger is called LoggerContext.updateLoggers must be called.
+ * Add a loggerConfig. The LoggerConfig must already be configured with Appenders, Filters, etc. After addLogger is
+ * called LoggerContext.updateLoggers must be called.
*
* @param loggerName The name of the Logger.
* @param loggerConfig The LoggerConfig.
@@ -745,42 +763,42 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
}
}
- /**
- * Invokes a static factory method to either create the desired object or to create a builder object that creates
- * the desired object. In the case of a factory method, it should be annotated with
- * {@link org.apache.logging.log4j.core.config.plugins.PluginFactory}, and each parameter should be annotated with
- * an appropriate plugin annotation depending on what that parameter describes. Parameters annotated with
- * {@link org.apache.logging.log4j.core.config.plugins.PluginAttribute} must be a type that can be converted from
- * a string using one of the {@link org.apache.logging.log4j.core.config.plugins.convert.TypeConverter TypeConverters}.
- * Parameters with {@link org.apache.logging.log4j.core.config.plugins.PluginElement} may be any plugin class or an
- * array of a plugin class. Collections and Maps are currently not supported, although the factory method that is
- * called can create these from an array.
- *
- * Plugins can also be created using a builder class that implements
- * {@link org.apache.logging.log4j.core.util.Builder}. In that case, a static method annotated with
- * {@link org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute} should create the builder class,
- * and the various fields in the builder class should be annotated similarly to the method parameters. However,
- * instead of using PluginAttribute, one should use
- * {@link org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute} where the default value can be
- * specified as the default field value instead of as an additional annotation parameter.
- *
- * In either case, there are also annotations for specifying a
- * {@link org.apache.logging.log4j.core.config.Configuration}
- * ({@link org.apache.logging.log4j.core.config.plugins.PluginConfiguration}) or a
- * {@link org.apache.logging.log4j.core.config.Node}
- * ({@link org.apache.logging.log4j.core.config.plugins.PluginNode}).
- *
- * Although the happy path works, more work still needs to be done to log incorrect
- * parameters. These will generally result in unhelpful InvocationTargetExceptions.
- *
- * @param type the type of plugin to create.
- * @param node the corresponding configuration node for this plugin to create.
- * @param event the LogEvent that spurred the creation of this plugin
- * @return the created plugin object or {@code null} if there was an error setting it up.
- * @see org.apache.logging.log4j.core.config.plugins.util.PluginBuilder
- * @see org.apache.logging.log4j.core.config.plugins.visitors.PluginVisitor
- * @see org.apache.logging.log4j.core.config.plugins.convert.TypeConverter
- */
+ /**
+ * Invokes a static factory method to either create the desired object or to create a builder object that creates
+ * the desired object. In the case of a factory method, it should be annotated with
+ * {@link org.apache.logging.log4j.core.config.plugins.PluginFactory}, and each parameter should be annotated with
+ * an appropriate plugin annotation depending on what that parameter describes. Parameters annotated with
+ * {@link org.apache.logging.log4j.core.config.plugins.PluginAttribute} must be a type that can be converted from a
+ * string using one of the {@link org.apache.logging.log4j.core.config.plugins.convert.TypeConverter TypeConverters}
+ * . Parameters with {@link org.apache.logging.log4j.core.config.plugins.PluginElement} may be any plugin class or
+ * an array of a plugin class. Collections and Maps are currently not supported, although the factory method that is
+ * called can create these from an array.
+ *
+ * Plugins can also be created using a builder class that implements
+ * {@link org.apache.logging.log4j.core.util.Builder}. In that case, a static method annotated with
+ * {@link org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute} should create the builder class, and
+ * the various fields in the builder class should be annotated similarly to the method parameters. However, instead
+ * of using PluginAttribute, one should use
+ * {@link org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute} where the default value can be
+ * specified as the default field value instead of as an additional annotation parameter.
+ *
+ * In either case, there are also annotations for specifying a
+ * {@link org.apache.logging.log4j.core.config.Configuration} (
+ * {@link org.apache.logging.log4j.core.config.plugins.PluginConfiguration}) or a
+ * {@link org.apache.logging.log4j.core.config.Node} (
+ * {@link org.apache.logging.log4j.core.config.plugins.PluginNode}).
+ *
+ * Although the happy path works, more work still needs to be done to log incorrect parameters. These will generally
+ * result in unhelpful InvocationTargetExceptions.
+ *
+ * @param type the type of plugin to create.
+ * @param node the corresponding configuration node for this plugin to create.
+ * @param event the LogEvent that spurred the creation of this plugin
+ * @return the created plugin object or {@code null} if there was an error setting it up.
+ * @see org.apache.logging.log4j.core.config.plugins.util.PluginBuilder
+ * @see org.apache.logging.log4j.core.config.plugins.visitors.PluginVisitor
+ * @see org.apache.logging.log4j.core.config.plugins.convert.TypeConverter
+ */
private Object createPluginObject(final PluginType<?> type, final Node node, final LogEvent event) {
final Class<?> clazz = type.getPluginClass();
@@ -800,11 +818,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
}
}
- return new PluginBuilder(type)
- .withConfiguration(this)
- .withConfigurationNode(node)
- .forLogEvent(event)
- .build();
+ return new PluginBuilder(type).withConfiguration(this).withConfigurationNode(node).forLogEvent(event).build();
}
private static Map<String, ?> createPluginMap(final Node node) {
@@ -827,7 +841,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
}
private void setParents() {
- for (final Map.Entry<String, LoggerConfig> entry : loggers.entrySet()) {
+ for (final Map.Entry<String, LoggerConfig> entry : loggers.entrySet()) {
final LoggerConfig logger = entry.getValue();
String key = entry.getKey();
if (!key.isEmpty()) {
@@ -847,8 +861,8 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
}
/**
- * Reads an InputStream using buffered reads into a byte array buffer. The given InputStream will remain open
- * after invocation of this method.
+ * Reads an InputStream using buffered reads into a byte array buffer. The given InputStream will remain open after
+ * invocation of this method.
*
* @param is the InputStream to read into a byte array buffer.
* @return a byte array of the InputStream contents.
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8606650e/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AppenderControl.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AppenderControl.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AppenderControl.java
index 01b97ce..09d837e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AppenderControl.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AppenderControl.java
@@ -40,6 +40,7 @@ public class AppenderControl extends AbstractFilterable {
/**
* Constructor.
+ *
* @param appender The target Appender.
* @param level the Level to filter on.
* @param filter the Filter(s) to apply.
@@ -52,9 +53,10 @@ public class AppenderControl extends AbstractFilterable {
this.intLevel = level == null ? Level.ALL.intLevel() : level.intLevel();
start();
}
-
+
/**
* Returns the name the appender had when this AppenderControl was constructed.
+ *
* @return the appender name
*/
public String getAppenderName() {
@@ -63,6 +65,7 @@ public class AppenderControl extends AbstractFilterable {
/**
* Returns the Appender.
+ *
* @return the Appender.
*/
public Appender getAppender() {
@@ -71,6 +74,7 @@ public class AppenderControl extends AbstractFilterable {
/**
* Call the appender.
+ *
* @param event The event to process.
*/
public void callAppender(final LogEvent event) {
@@ -99,7 +103,7 @@ public class AppenderControl extends AbstractFilterable {
}
return false;
}
-
+
private String appenderErrorHandlerMessage(final String prefix) {
String result = createErrorMsg(prefix);
appender.getHandler().error(result);
@@ -108,7 +112,7 @@ public class AppenderControl extends AbstractFilterable {
private void callAppenderPreventRecursion(final LogEvent event) {
try {
- recursive.set(this);
+ recursive.set(this);
callAppender0(event);
} finally {
recursive.set(null);
@@ -138,7 +142,7 @@ public class AppenderControl extends AbstractFilterable {
private String createErrorMsg(final String prefix) {
return prefix + appender.getName();
}
-
+
private boolean isFilteredByAppender(final LogEvent event) {
return appender instanceof Filterable && ((Filterable) appender).isFiltered(event);
}
@@ -159,7 +163,7 @@ public class AppenderControl extends AbstractFilterable {
throw ex;
}
}
-
+
// AppenderControl is a helper object whose purpose is to make it
// easier for LoggerConfig to manage and invoke Appenders.
// LoggerConfig manages Appenders by their name. To facilitate this,
@@ -176,7 +180,7 @@ public class AppenderControl extends AbstractFilterable {
final AppenderControl other = (AppenderControl) obj;
return Objects.equals(appenderName, other.appenderName);
}
-
+
@Override
public int hashCode() {
return appenderName.hashCode();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8606650e/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AwaitCompletionReliabilityStrategy.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AwaitCompletionReliabilityStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AwaitCompletionReliabilityStrategy.java
index 4251cfa..b94224c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AwaitCompletionReliabilityStrategy.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AwaitCompletionReliabilityStrategy.java
@@ -47,8 +47,12 @@ public class AwaitCompletionReliabilityStrategy implements ReliabilityStrategy {
this.loggerConfig = Objects.requireNonNull(loggerConfig, "loggerConfig is null");
}
- /* (non-Javadoc)
- * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#log(org.apache.logging.log4j.util.Supplier, java.lang.String, java.lang.String, org.apache.logging.log4j.Marker, org.apache.logging.log4j.Level, org.apache.logging.log4j.message.Message, java.lang.Throwable)
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#log(org.apache.logging.log4j.util.Supplier,
+ * java.lang.String, java.lang.String, org.apache.logging.log4j.Marker, org.apache.logging.log4j.Level,
+ * org.apache.logging.log4j.message.Message, java.lang.Throwable)
*/
@Override
public void log(final Supplier<LoggerConfig> reconfigured, final String loggerName, final String fqcn,
@@ -62,8 +66,11 @@ public class AwaitCompletionReliabilityStrategy implements ReliabilityStrategy {
}
}
- /* (non-Javadoc)
- * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#log(org.apache.logging.log4j.util.Supplier, org.apache.logging.log4j.core.LogEvent)
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#log(org.apache.logging.log4j.util.Supplier,
+ * org.apache.logging.log4j.core.LogEvent)
*/
@Override
public void log(final Supplier<LoggerConfig> reconfigured, final LogEvent event) {
@@ -75,8 +82,12 @@ public class AwaitCompletionReliabilityStrategy implements ReliabilityStrategy {
}
}
- /* (non-Javadoc)
- * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeLogEvent(org.apache.logging.log4j.core.config.LoggerConfig, org.apache.logging.log4j.util.Supplier)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeLogEvent(org.apache.logging.log4j.core.config.
+ * LoggerConfig, org.apache.logging.log4j.util.Supplier)
*/
@Override
public LoggerConfig getActiveLoggerConfig(final Supplier<LoggerConfig> next) {
@@ -108,7 +119,9 @@ public class AwaitCompletionReliabilityStrategy implements ReliabilityStrategy {
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopAppenders()
*/
@Override
@@ -146,8 +159,12 @@ public class AwaitCompletionReliabilityStrategy implements ReliabilityStrategy {
}
}
- /* (non-Javadoc)
- * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopConfiguration(org.apache.logging.log4j.core.config.Configuration)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopConfiguration(org.apache.logging.log4j.core
+ * .config.Configuration)
*/
@Override
public void beforeStopConfiguration(Configuration configuration) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8606650e/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AwaitUnconditionallyReliabilityStrategy.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AwaitUnconditionallyReliabilityStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AwaitUnconditionallyReliabilityStrategy.java
index 750af31..5e0456c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AwaitUnconditionallyReliabilityStrategy.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AwaitUnconditionallyReliabilityStrategy.java
@@ -39,7 +39,7 @@ public class AwaitUnconditionallyReliabilityStrategy implements ReliabilityStrat
public AwaitUnconditionallyReliabilityStrategy(final LoggerConfig loggerConfig) {
this.loggerConfig = Objects.requireNonNull(loggerConfig, "loggerConfig is null");
}
-
+
private static long sleepMillis() {
return PropertiesUtil.getProperties().getLongProperty("log4j.waitMillisBeforeStopOldConfig",
DEFAULT_SLEEP_MILLIS);
@@ -101,8 +101,12 @@ public class AwaitUnconditionallyReliabilityStrategy implements ReliabilityStrat
// no action
}
- /* (non-Javadoc)
- * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopConfiguration(org.apache.logging.log4j.core.config.Configuration)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopConfiguration(org.apache.logging.log4j.core
+ * .config.Configuration)
*/
@Override
public void beforeStopConfiguration(Configuration configuration) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8606650e/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LockingReliabilityStrategy.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LockingReliabilityStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LockingReliabilityStrategy.java
index f518ba1..5bc4f97 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LockingReliabilityStrategy.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LockingReliabilityStrategy.java
@@ -39,8 +39,12 @@ public class LockingReliabilityStrategy implements ReliabilityStrategy {
this.loggerConfig = Objects.requireNonNull(loggerConfig, "loggerConfig was null");
}
- /* (non-Javadoc)
- * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#log(org.apache.logging.log4j.util.Supplier, java.lang.String, java.lang.String, org.apache.logging.log4j.Marker, org.apache.logging.log4j.Level, org.apache.logging.log4j.message.Message, java.lang.Throwable)
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#log(org.apache.logging.log4j.util.Supplier,
+ * java.lang.String, java.lang.String, org.apache.logging.log4j.Marker, org.apache.logging.log4j.Level,
+ * org.apache.logging.log4j.message.Message, java.lang.Throwable)
*/
@Override
public void log(final Supplier<LoggerConfig> reconfigured, final String loggerName, final String fqcn,
@@ -54,8 +58,11 @@ public class LockingReliabilityStrategy implements ReliabilityStrategy {
}
}
- /* (non-Javadoc)
- * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#log(org.apache.logging.log4j.util.Supplier, org.apache.logging.log4j.core.LogEvent)
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#log(org.apache.logging.log4j.util.Supplier,
+ * org.apache.logging.log4j.core.LogEvent)
*/
@Override
public void log(final Supplier<LoggerConfig> reconfigured, final LogEvent event) {
@@ -67,8 +74,12 @@ public class LockingReliabilityStrategy implements ReliabilityStrategy {
}
}
- /* (non-Javadoc)
- * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeLogEvent(org.apache.logging.log4j.core.config.LoggerConfig, org.apache.logging.log4j.util.Supplier)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeLogEvent(org.apache.logging.log4j.core.config.
+ * LoggerConfig, org.apache.logging.log4j.util.Supplier)
*/
@Override
public LoggerConfig getActiveLoggerConfig(final Supplier<LoggerConfig> next) {
@@ -93,7 +104,9 @@ public class LockingReliabilityStrategy implements ReliabilityStrategy {
reconfigureLock.readLock().unlock();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopAppenders()
*/
@Override
@@ -106,8 +119,12 @@ public class LockingReliabilityStrategy implements ReliabilityStrategy {
}
}
- /* (non-Javadoc)
- * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopConfiguration(org.apache.logging.log4j.core.config.Configuration)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopConfiguration(org.apache.logging.log4j.core
+ * .config.Configuration)
*/
@Override
public void beforeStopConfiguration(Configuration configuration) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8606650e/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
index 8a26335..5f58a79 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
@@ -23,8 +23,11 @@ import org.apache.logging.log4j.Level;
*/
public class NullConfiguration extends AbstractConfiguration {
- private static final long serialVersionUID = 1L;
+ /**
+ * Name of this configuration.
+ */
public static final String NULL_NAME = "Null";
+ private static final long serialVersionUID = 1L;
public NullConfiguration() {
super(ConfigurationSource.NULL_SOURCE);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8606650e/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategy.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategy.java
index 3c86d9c..e85eef6 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategy.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategy.java
@@ -32,6 +32,7 @@ public interface ReliabilityStrategy {
/**
* Logs an event.
*
+ * @param reconfigured supplies the next LoggerConfig if the strategy's LoggerConfig is no longer active
* @param loggerName The name of the Logger.
* @param fqcn The fully qualified class name of the caller.
* @param marker A Marker or null if none is present.
@@ -39,20 +40,22 @@ public interface ReliabilityStrategy {
* @param data The Message.
* @param t A Throwable or null.
*/
- void log(Supplier<LoggerConfig> reconfigured, String loggerName, String fqcn, Marker marker,
- Level level, Message data, Throwable t);
+ void log(Supplier<LoggerConfig> reconfigured, String loggerName, String fqcn, Marker marker, Level level,
+ Message data, Throwable t);
/**
* Logs an event.
*
+ * @param reconfigured supplies the next LoggerConfig if the strategy's LoggerConfig is no longer active
* @param event The log event.
*/
void log(Supplier<LoggerConfig> reconfigured, LogEvent event);
/**
* For internal use by the ReliabilityStrategy; returns the LoggerConfig to use.
- * @param next
- * @return
+ *
+ * @param next supplies the next LoggerConfig if the strategy's LoggerConfig is no longer active
+ * @return the currently active LoggerConfig
*/
LoggerConfig getActiveLoggerConfig(Supplier<LoggerConfig> next);
@@ -60,7 +63,7 @@ public interface ReliabilityStrategy {
* Called after a log event was logged.
*/
void afterLogEvent();
-
+
/**
* Called before all appenders are stopped.
*/
@@ -69,7 +72,7 @@ public interface ReliabilityStrategy {
/**
* Called before the configuration is stopped.
*
- * @param configuration
+ * @param configuration the configuration that will be stopped
*/
void beforeStopConfiguration(Configuration configuration);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8606650e/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategyFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategyFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategyFactory.java
index 8fd9458..1c8ef53 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategyFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategyFactory.java
@@ -23,7 +23,7 @@ import org.apache.logging.log4j.util.PropertiesUtil;
/**
* Factory for ReliabilityStrategies.
*/
-public class ReliabilityStrategyFactory {
+public final class ReliabilityStrategyFactory {
private ReliabilityStrategyFactory() {
}