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/1236fac8 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1236fac8 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1236fac8 Branch: refs/heads/LOG4J2-1136 Commit: 1236fac8b2eddcd18ebe345c4d8270444f23ef07 Parents: 951cbbd Author: rpopma <[email protected]> Authored: Thu Sep 24 14:09:38 2015 +0200 Committer: Ralph Goers <[email protected]> Committed: Sun Sep 27 10:47:30 2015 -0700 ---------------------------------------------------------------------- .../org/apache/logging/log4j/core/Logger.java | 95 ++++--- .../logging/log4j/core/LoggerContext.java | 254 ++++++++++--------- .../log4j/core/appender/AbstractAppender.java | 47 ++-- .../appender/AbstractOutputStreamAppender.java | 27 +- .../log4j/core/appender/AsyncAppender.java | 65 +++-- .../log4j/core/appender/ConsoleAppender.java | 68 ++--- .../core/appender/MemoryMappedFileManager.java | 17 +- .../core/appender/RandomAccessFileManager.java | 4 +- .../core/appender/RollingFileAppender.java | 3 +- 9 files changed, 308 insertions(+), 272 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1236fac8/log4j-core/src/main/java/org/apache/logging/log4j/core/Logger.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/Logger.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/Logger.java index 48f350b..40852a5 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/Logger.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/Logger.java @@ -36,17 +36,16 @@ import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Supplier; /** - * The core implementation of the {@link org.apache.logging.log4j.Logger} interface. Besides providing an - * implementation of all the Logger methods, this class also provides some convenience methods for Log4j 1.x - * compatibility as well as access to the {@link org.apache.logging.log4j.core.Filter Filters} and - * {@link org.apache.logging.log4j.core.Appender Appenders} associated with this Logger. Note that access to these - * underlying objects is provided primarily for use in unit tests or bridging legacy Log4j 1.x code. Future versions - * of this class may or may not include the various methods that are noted as not being part of the public API. + * The core implementation of the {@link org.apache.logging.log4j.Logger} interface. Besides providing an implementation + * of all the Logger methods, this class also provides some convenience methods for Log4j 1.x compatibility as well as + * access to the {@link org.apache.logging.log4j.core.Filter Filters} and {@link org.apache.logging.log4j.core.Appender + * Appenders} associated with this Logger. Note that access to these underlying objects is provided primarily for use in + * unit tests or bridging legacy Log4j 1.x code. Future versions of this class may or may not include the various + * methods that are noted as not being part of the public API. * - * TODO All the isEnabled methods could be pushed into a filter interface. Not sure of the utility of having - * isEnabled be able to examine the message pattern and parameters. (RG) Moving the isEnabled methods out of - * Logger noticeably impacts performance. The message pattern and parameters are required so that they can be - * used in global filters. + * TODO All the isEnabled methods could be pushed into a filter interface. Not sure of the utility of having isEnabled + * be able to examine the message pattern and parameters. (RG) Moving the isEnabled methods out of Logger noticeably + * impacts performance. The message pattern and parameters are required so that they can be used in global filters. */ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { @@ -62,6 +61,7 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { /** * The constructor. + * * @param context The LoggerContext this Logger is associated with. * @param messageFactory The message factory. * @param name The name of the Logger. @@ -73,13 +73,14 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { } /** - * This method is only used for 1.x compatibility. - * Returns the parent of this Logger. If it doesn't already exist return a temporary Logger. + * This method is only used for 1.x compatibility. Returns the parent of this Logger. If it doesn't already exist + * return a temporary Logger. + * * @return The parent Logger. */ public Logger getParent() { - final LoggerConfig lc = privateConfig.loggerConfig.getName().equals(getName()) ? privateConfig.loggerConfig.getParent() : - privateConfig.loggerConfig; + final LoggerConfig lc = privateConfig.loggerConfig.getName().equals(getName()) ? privateConfig.loggerConfig + .getParent() : privateConfig.loggerConfig; if (lc == null) { return null; } @@ -91,6 +92,7 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { /** * Returns the LoggerContext this Logger is associated with. + * * @return the LoggerContext. */ public LoggerContext getContext() { @@ -114,13 +116,14 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { actualLevel = level; } else { final Logger parent = getParent(); - actualLevel = parent != null ? parent.getLevel() : privateConfig.level; + actualLevel = parent != null ? parent.getLevel() : privateConfig.loggerConfigLevel; } privateConfig = new PrivateConfig(privateConfig, actualLevel); } - + /* * (non-Javadoc) + * * @see org.apache.logging.log4j.util.Supplier#get() */ @Override @@ -129,12 +132,13 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { } @Override - public void logMessage(final String fqcn, final Level level, final Marker marker, final Message message, final Throwable t) { + public void logMessage(final String fqcn, final Level level, final Marker marker, final Message message, + final Throwable t) { final Message msg = message == null ? new SimpleMessage(Strings.EMPTY) : message; - + // check if we need to reconfigure privateConfig.config.getConfigurationMonitor().checkConfiguration(); - + final ReliabilityStrategy strategy = privateConfig.loggerConfig.getReliabilityStrategy(); strategy.log(this, getName(), fqcn, marker, level, msg, t); } @@ -166,6 +170,7 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { /** * This method is not exposed through the public API and is used primarily for unit testing. + * * @param appender The Appender to add to the Logger. */ public void addAppender(final Appender appender) { @@ -174,6 +179,7 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { /** * This method is not exposed through the public API and is used primarily for unit testing. + * * @param appender The Appender to remove from the Logger. */ public void removeAppender(final Appender appender) { @@ -182,14 +188,16 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { /** * This method is not exposed through the public API and is used primarily for unit testing. + * * @return A Map containing the Appender's name as the key and the Appender as the value. */ public Map<String, Appender> getAppenders() { - return privateConfig.loggerConfig.getAppenders(); + return privateConfig.loggerConfig.getAppenders(); } /** * This method is not exposed through the public API and is used primarily for unit testing. + * * @return An Iterator over all the Filters associated with the Logger. */ // FIXME: this really ought to be an Iterable instead of an Iterator @@ -213,11 +221,12 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { */ @Override public Level getLevel() { - return privateConfig.level; + return privateConfig.loggerConfigLevel; } /** * This method is not exposed through the public API and is used primarily for unit testing. + * * @return The number of Filters associated with the Logger. */ public int filterCount() { @@ -232,6 +241,7 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { /** * This method is not exposed through the public API and is used primarily for unit testing. + * * @param filter The Filter to add. */ public void addFilter(final Filter filter) { @@ -239,8 +249,9 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { } /** - * This method is not exposed through the public API and is present only to support the Log4j 1.2 - * compatibility bridge. + * This method is not exposed through the public API and is present only to support the Log4j 1.2 compatibility + * bridge. + * * @return true if the associated LoggerConfig is additive, false otherwise. */ public boolean isAdditive() { @@ -248,8 +259,9 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { } /** - * This method is not exposed through the public API and is present only to support the Log4j 1.2 - * compatibility bridge. + * This method is not exposed through the public API and is present only to support the Log4j 1.2 compatibility + * bridge. + * * @param additive Boolean value to indicate whether the Logger is additive or not. */ public void setAdditive(final boolean additive) { @@ -257,14 +269,12 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { } /** - * Associates the Logger with a new Configuration. This method is not exposed through the - * public API. + * Associates the Logger with a new Configuration. This method is not exposed through the public API. * - * There are two ways that could be used to guarantee all threads are aware of changes to - * config. 1. synchronize this method. Accessors don't need to be synchronized as Java will - * treat all variables within a synchronized block as volatile. 2. Declare the variable - * volatile. Option 2 is used here as the performance cost is very low and it does a better - * job at documenting how it is used. + * There are two ways that could be used to guarantee all threads are aware of changes to config. 1. synchronize + * this method. Accessors don't need to be synchronized as Java will treat all variables within a synchronized block + * as volatile. 2. Declare the variable volatile. Option 2 is used here as the performance cost is very low and it + * does a better job at documenting how it is used. * * @param newConfig The new Configuration. */ @@ -279,33 +289,35 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { protected class PrivateConfig implements Serializable { private static final long serialVersionUID = 1L; // config fields are public to make them visible to Logger subclasses - public final LoggerConfig loggerConfig; - public final Configuration config; - private final Level level; + /** LoggerConfig to delegate the actual logging to. */ + public final LoggerConfig loggerConfig; // SUPPRESS CHECKSTYLE + /** The current Configuration associated with the LoggerConfig. */ + public final Configuration config; // SUPPRESS CHECKSTYLE + private final Level loggerConfigLevel; private final int intLevel; private final Logger logger; public PrivateConfig(final Configuration config, final Logger logger) { this.config = config; this.loggerConfig = config.getLoggerConfig(getName()); - this.level = this.loggerConfig.getLevel(); - this.intLevel = this.level.intLevel(); + this.loggerConfigLevel = this.loggerConfig.getLevel(); + this.intLevel = this.loggerConfigLevel.intLevel(); this.logger = logger; } public PrivateConfig(final PrivateConfig pc, final Level level) { this.config = pc.config; this.loggerConfig = pc.loggerConfig; - this.level = level; - this.intLevel = this.level.intLevel(); + this.loggerConfigLevel = level; + this.intLevel = this.loggerConfigLevel.intLevel(); this.logger = pc.logger; } public PrivateConfig(final PrivateConfig pc, final LoggerConfig lc) { this.config = pc.config; this.loggerConfig = lc; - this.level = lc.getLevel(); - this.intLevel = this.level.intLevel(); + this.loggerConfigLevel = lc.getLevel(); + this.intLevel = this.loggerConfigLevel.intLevel(); this.logger = pc.logger; } @@ -378,6 +390,7 @@ public class Logger extends AbstractLogger implements Supplier<LoggerConfig> { /** * Returns a String representation of this instance in the form {@code "name:level[ in context_name]"}. + * * @return A String describing this Logger instance. */ @Override http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1236fac8/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java index 6f37306..841080c 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java @@ -33,7 +33,7 @@ import org.apache.logging.log4j.core.async.AsyncLogger; import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.ConfigurationFactory; import org.apache.logging.log4j.core.config.ConfigurationListener; -import org.apache.logging.log4j.core.config.ConfigurationSource; +import org.apache.logging.log4j.core.config.ConfigurationSource; // SUPPRESS CHECKSTYLE import org.apache.logging.log4j.core.config.DefaultConfiguration; import org.apache.logging.log4j.core.config.NullConfiguration; import org.apache.logging.log4j.core.config.Reconfigurable; @@ -50,87 +50,31 @@ import org.apache.logging.log4j.spi.LoggerContextFactory; import static org.apache.logging.log4j.core.util.ShutdownCallbackRegistry.*; /** - * The LoggerContext is the anchor for the logging system. It maintains a list - * of all the loggers requested by applications and a reference to the - * Configuration. The Configuration will contain the configured loggers, - * appenders, filters, etc and will be atomically updated whenever a reconfigure - * occurs. + * The LoggerContext is the anchor for the logging system. It maintains a list of all the loggers requested by + * applications and a reference to the Configuration. The Configuration will contain the configured loggers, appenders, + * filters, etc and will be atomically updated whenever a reconfigure occurs. */ -public class LoggerContext extends AbstractLifeCycle implements org.apache.logging.log4j.spi.LoggerContext, ConfigurationListener { - - private static final long serialVersionUID = 1L; - - public static final String PROPERTY_CONFIG = "config"; - private static final Configuration NULL_CONFIGURATION = new NullConfiguration(); +public class LoggerContext extends AbstractLifeCycle implements org.apache.logging.log4j.spi.LoggerContext, + ConfigurationListener { /** - * Returns the current LoggerContext. - * <p> - * Avoids the type cast for: - *</p> - *<pre>(LoggerContext) LogManager.getContext();</pre> - * - * <p> - * WARNING - The LoggerContext returned by this method may not be the LoggerContext used to create a Logger - * for the calling class. - * </p> - * @return The current LoggerContext. - * @see LogManager#getContext() + * Property name of the property change event fired if the configuration is changed. */ - public static LoggerContext getContext() { - return (LoggerContext) LogManager.getContext(); - } - - /** - * Returns a LoggerContext. - * <p> - * Avoids the type cast for: - *</p> - *<pre>(LoggerContext) LogManager.getContext(currentContext);</pre> - * - * @param currentContext if false the LoggerContext appropriate for the caller of this method is returned. For - * example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be - * returned and if the caller is a class in the container's classpath then a different LoggerContext may be - * returned. If true then only a single LoggerContext will be returned. - * @return a LoggerContext. - * @see LogManager#getContext(boolean) - */ - public static LoggerContext getContext(final boolean currentContext) { - return (LoggerContext) LogManager.getContext(currentContext); - } + public static final String PROPERTY_CONFIG = "config"; - /** - * Returns a LoggerContext. - * <p> - * Avoids the type cast for: - *</p> - *<pre>(LoggerContext) LogManager.getContext(loader, currentContext, configLocation);</pre> - * - * @param loader The ClassLoader for the context. If null the context will attempt to determine the appropriate - * ClassLoader. - * @param currentContext if false the LoggerContext appropriate for the caller of this method is returned. For - * example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be - * returned and if the caller is a class in the container's classpath then a different LoggerContext may be - * returned. If true then only a single LoggerContext will be returned. - * @param configLocation The URI for the configuration to use. - * @return a LoggerContext. - * @see LogManager#getContext(ClassLoader, boolean, URI) - */ - public static LoggerContext getContext(final ClassLoader loader, final boolean currentContext, - final URI configLocation) { - return (LoggerContext) LogManager.getContext(loader, currentContext, configLocation); - } + private static final long serialVersionUID = 1L; + private static final Configuration NULL_CONFIGURATION = new NullConfiguration(); private final ConcurrentMap<String, Logger> loggers = new ConcurrentHashMap<>(); private final CopyOnWriteArrayList<PropertyChangeListener> propertyChangeListeners = new CopyOnWriteArrayList<>(); /** - * The Configuration is volatile to guarantee that initialization of the - * Configuration has completed before the reference is updated. + * The Configuration is volatile to guarantee that initialization of the Configuration has completed before the + * reference is updated. */ - private volatile Configuration config = new DefaultConfiguration(); + private volatile Configuration configuration = new DefaultConfiguration(); private Object externalContext; - private final String name; + private final String contextName; private volatile URI configLocation; private Cancellable shutdownCallback; @@ -138,6 +82,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi /** * Constructor taking only a name. + * * @param name The context name. */ public LoggerContext(final String name) { @@ -146,6 +91,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi /** * Constructor taking a name and a reference to an external context. + * * @param name The context name. * @param externalContext The external context. */ @@ -155,26 +101,27 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi /** * Constructor taking a name, external context and a configuration URI. + * * @param name The context name. * @param externalContext The external context. * @param configLocn The location of the configuration as a URI. */ public LoggerContext(final String name, final Object externalContext, final URI configLocn) { - this.name = name; + this.contextName = name; this.externalContext = externalContext; this.configLocation = configLocn; } /** - * Constructor taking a name external context and a configuration location - * String. The location must be resolvable to a File. + * Constructor taking a name external context and a configuration location String. The location must be resolvable + * to a File. * * @param name The configuration location. * @param externalContext The external context. * @param configLocn The configuration location. */ public LoggerContext(final String name, final Object externalContext, final String configLocn) { - this.name = name; + this.contextName = name; this.externalContext = externalContext; if (configLocn != null) { URI uri; @@ -189,6 +136,74 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi } } + /** + * Returns the current LoggerContext. + * <p> + * Avoids the type cast for: + * </p> + * + * <pre> + * (LoggerContext) LogManager.getContext(); + * </pre> + * + * <p> + * WARNING - The LoggerContext returned by this method may not be the LoggerContext used to create a Logger for the + * calling class. + * </p> + * + * @return The current LoggerContext. + * @see LogManager#getContext() + */ + public static LoggerContext getContext() { + return (LoggerContext) LogManager.getContext(); + } + + /** + * Returns a LoggerContext. + * <p> + * Avoids the type cast for: + * </p> + * + * <pre> + * (LoggerContext) LogManager.getContext(currentContext); + * </pre> + * + * @param currentContext if false the LoggerContext appropriate for the caller of this method is returned. For + * example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be + * returned and if the caller is a class in the container's classpath then a different LoggerContext may + * be returned. If true then only a single LoggerContext will be returned. + * @return a LoggerContext. + * @see LogManager#getContext(boolean) + */ + public static LoggerContext getContext(final boolean currentContext) { + return (LoggerContext) LogManager.getContext(currentContext); + } + + /** + * Returns a LoggerContext. + * <p> + * Avoids the type cast for: + * </p> + * + * <pre> + * (LoggerContext) LogManager.getContext(loader, currentContext, configLocation); + * </pre> + * + * @param loader The ClassLoader for the context. If null the context will attempt to determine the appropriate + * ClassLoader. + * @param currentContext if false the LoggerContext appropriate for the caller of this method is returned. For + * example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be + * returned and if the caller is a class in the container's classpath then a different LoggerContext may + * be returned. If true then only a single LoggerContext will be returned. + * @param configLocation The URI for the configuration to use. + * @return a LoggerContext. + * @see LogManager#getContext(ClassLoader, boolean, URI) + */ + public static LoggerContext getContext(final ClassLoader loader, final boolean currentContext, + final URI configLocation) { + return (LoggerContext) LogManager.getContext(loader, currentContext, configLocation); + } + @Override public void start() { LOGGER.debug("Starting LoggerContext[name={}, {}]...", getName(), this); @@ -197,7 +212,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi if (this.isInitialized() || this.isStopped()) { this.setStarting(); reconfigure(); - if (this.config.isShutdownHookEnabled()) { + if (this.configuration.isShutdownHookEnabled()) { setUpShutdownHook(); } this.setStarted(); @@ -211,6 +226,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi /** * Starts with a specific configuration. + * * @param config The new Configuration. */ public void start(final Configuration config) { @@ -218,7 +234,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi if (configLock.tryLock()) { try { if (this.isInitialized() || this.isStopped()) { - if (this.config.isShutdownHookEnabled()) { + if (this.configuration.isShutdownHookEnabled()) { setUpShutdownHook(); } this.setStarted(); @@ -241,8 +257,8 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi @Override public void run() { final LoggerContext context = LoggerContext.this; - LOGGER.debug(SHUTDOWN_HOOK_MARKER, "Stopping LoggerContext[name={}, {}]", context.getName(), - context); + LOGGER.debug(SHUTDOWN_HOOK_MARKER, "Stopping LoggerContext[name={}, {}]", + context.getName(), context); context.stop(); } @@ -252,9 +268,11 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi } }); } catch (final IllegalStateException e) { - LOGGER.fatal(SHUTDOWN_HOOK_MARKER, "Unable to register shutdown hook because JVM is shutting down.", e); + LOGGER.fatal(SHUTDOWN_HOOK_MARKER, + "Unable to register shutdown hook because JVM is shutting down.", e); } catch (final SecurityException e) { - LOGGER.error(SHUTDOWN_HOOK_MARKER, "Unable to register shutdown hook due to security restrictions", e); + LOGGER.error(SHUTDOWN_HOOK_MARKER, "Unable to register shutdown hook due to security restrictions", + e); } } } @@ -279,8 +297,8 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi shutdownCallback.cancel(); shutdownCallback = null; } - final Configuration prev = config; - config = NULL_CONFIGURATION; + final Configuration prev = configuration; + configuration = NULL_CONFIGURATION; updateLoggers(); prev.stop(); externalContext = null; @@ -298,11 +316,12 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi * @return the name. */ public String getName() { - return name; + return contextName; } /** * Sets the external context. + * * @param context The external context. */ public void setExternalContext(final Object context) { @@ -311,6 +330,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi /** * Returns the external context. + * * @return The external context. */ @Override @@ -320,6 +340,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi /** * Obtains a Logger from the Context. + * * @param name The name of the Logger to return. * @return The Logger. */ @@ -331,8 +352,8 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi /** * Gets a collection of the current loggers. * <p> - * Whether this collection is a copy of the underlying collection or not is undefined. Therefore, modify this collection at your own - * risk. + * Whether this collection is a copy of the underlying collection or not is undefined. Therefore, modify this + * collection at your own risk. * </p> * * @return a collection of the current loggers. @@ -343,10 +364,10 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi /** * Obtains a Logger from the Context. + * * @param name The name of the Logger to return. - * @param messageFactory The message factory is used only when creating a - * logger, subsequent use does not change the logger but will log - * a warning if mismatched. + * @param messageFactory The message factory is used only when creating a logger, subsequent use does not change the + * logger but will log a warning if mismatched. * @return The Logger. */ @Override @@ -364,6 +385,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi /** * Determines if the specified Logger exists. + * * @param name The Logger name to search for. * @return True if the Logger exists, false otherwise. */ @@ -373,34 +395,36 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi } /** - * Returns the current Configuration. The Configuration will be replaced - * when a reconfigure occurs. + * Returns the current Configuration. The Configuration will be replaced when a reconfigure occurs. * * @return The Configuration. */ public Configuration getConfiguration() { - return config; + return configuration; } /** - * Adds a Filter to the Configuration. Filters that are added through the API will be lost - * when a reconfigure occurs. + * Adds a Filter to the Configuration. Filters that are added through the API will be lost when a reconfigure + * occurs. + * * @param filter The Filter to add. */ public void addFilter(final Filter filter) { - config.addFilter(filter); + configuration.addFilter(filter); } /** * Removes a Filter from the current Configuration. + * * @param filter The Filter to remove. */ public void removeFilter(final Filter filter) { - config.removeFilter(filter); + configuration.removeFilter(filter); } /** * Sets the Configuration to be used. + * * @param config The new Configuration. * @return The previous Configuration. */ @@ -408,7 +432,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi Objects.requireNonNull(config, "No Configuration was provided"); configLock.lock(); try { - final Configuration prev = this.config; + final Configuration prev = this.configuration; config.addListener(this); final ConcurrentMap<String, String> map = config.getComponent(Configuration.CONTEXT_PROPERTIES); @@ -418,9 +442,9 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi LOGGER.debug("Ignoring {}, setting hostName to 'unknown'", ex.toString()); map.putIfAbsent("hostName", "unknown"); } - map.putIfAbsent("contextName", name); + map.putIfAbsent("contextName", contextName); config.start(); - this.config = config; + this.configuration = config; updateLoggers(); if (prev != null) { prev.removeListener(this); @@ -464,9 +488,10 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi /** * Returns the initial configuration location or {@code null}. The returned value may not be the location of the - * current configuration. Use - * {@link #getConfiguration()}.{@link Configuration#getConfigurationSource() getConfigurationSource()}.{@link - * ConfigurationSource#getLocation() getLocation()} to get the actual source of the current configuration. + * current configuration. Use {@link #getConfiguration()}.{@link Configuration#getConfigurationSource() + * getConfigurationSource()}.{@link ConfigurationSource#getLocation() getLocation()} to get the actual source of the + * current configuration. + * * @return the initial configuration location or {@code null} */ public URI getConfigLocation() { @@ -475,6 +500,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi /** * Sets the configLocation to the specified value and reconfigures this context. + * * @param configLocation the location of the new configuration */ public void setConfigLocation(final URI configLocation) { @@ -488,17 +514,17 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi */ private void reconfigure(final URI configURI) { final ClassLoader cl = ClassLoader.class.isInstance(externalContext) ? (ClassLoader) externalContext : null; - LOGGER.debug("Reconfiguration started for context[name={}] at URI {} ({}) with optional ClassLoader: {}", name, - configURI, this, cl); - final Configuration instance = ConfigurationFactory.getInstance().getConfiguration(name, configURI, cl); + LOGGER.debug("Reconfiguration started for context[name={}] at URI {} ({}) with optional ClassLoader: {}", + contextName, configURI, this, cl); + final Configuration instance = ConfigurationFactory.getInstance().getConfiguration(contextName, configURI, cl); setConfiguration(instance); /* - * instance.start(); Configuration old = setConfiguration(instance); - * updateLoggers(); if (old != null) { old.stop(); } + * instance.start(); Configuration old = setConfiguration(instance); updateLoggers(); if (old != null) { + * old.stop(); } */ - LOGGER.debug("Reconfiguration complete for context[name={}] at URI {} ({}) with optional ClassLoader: {}", name, - configURI, this, cl); + LOGGER.debug("Reconfiguration complete for context[name={}] at URI {} ({}) with optional ClassLoader: {}", + contextName, configURI, this, cl); } /** @@ -514,11 +540,12 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi * Causes all Loggers to be updated against the current Configuration. */ public void updateLoggers() { - updateLoggers(this.config); + updateLoggers(this.configuration); } /** * Causes all Logger to be updated against the specified Configuration. + * * @param config The Configuration. */ public void updateLoggers(final Configuration config) { @@ -528,20 +555,19 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi } /** - * Causes a reconfiguration to take place when the underlying configuration - * file changes. + * Causes a reconfiguration to take place when the underlying configuration file changes. * * @param reconfigurable The Configuration that can be reconfigured. */ @Override public synchronized void onChange(final Reconfigurable reconfigurable) { - LOGGER.debug("Reconfiguration started for context {} ({})", name, this); + LOGGER.debug("Reconfiguration started for context {} ({})", contextName, this); final Configuration newConfig = reconfigurable.reconfigure(); if (newConfig != null) { setConfiguration(newConfig); - LOGGER.debug("Reconfiguration completed for {} ({})", name, this); + LOGGER.debug("Reconfiguration completed for {} ({})", contextName, this); } else { - LOGGER.debug("Reconfiguration failed for {} ({})", name, this); + LOGGER.debug("Reconfiguration failed for {} ({})", contextName, this); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1236fac8/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractAppender.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractAppender.java index df04706..af01fc1 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractAppender.java @@ -27,33 +27,21 @@ import org.apache.logging.log4j.core.filter.AbstractFilterable; import org.apache.logging.log4j.core.util.Integers; /** - * Abstract base class for Appenders. Although Appenders do not have to extend this class, doing so - * will simplify their implementation. + * Abstract base class for Appenders. Although Appenders do not have to extend this class, doing so will simplify their + * implementation. */ -public abstract class AbstractAppender extends AbstractFilterable - implements Appender { +public abstract class AbstractAppender extends AbstractFilterable implements Appender { private static final long serialVersionUID = 1L; + private final String name; private final boolean ignoreExceptions; - - private ErrorHandler handler = new DefaultErrorHandler(this); - private final Layout<? extends Serializable> layout; - - private final String name; - - public static int parseInt(final String s, final int defaultValue) { - try { - return Integers.parseInt(s, defaultValue); - } catch (final NumberFormatException e) { - LOGGER.error("Could not parse \"{}\" as an integer, using default value {}: {}", s, defaultValue, e); - return defaultValue; - } - } + private ErrorHandler handler = new DefaultErrorHandler(this); /** * Constructor that defaults to suppressing exceptions. + * * @param name The Appender name. * @param filter The Filter to associate with the Appender. * @param layout The layout to use to format the event. @@ -64,22 +52,33 @@ public abstract class AbstractAppender extends AbstractFilterable /** * Constructor. + * * @param name The Appender name. * @param filter The Filter to associate with the Appender. * @param layout The layout to use to format the event. - * @param ignoreExceptions If true, exceptions will be logged and suppressed. If false errors will be - * logged and then passed to the application. + * @param ignoreExceptions If true, exceptions will be logged and suppressed. If false errors will be logged and + * then passed to the application. */ protected AbstractAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout, - final boolean ignoreExceptions) { + final boolean ignoreExceptions) { super(filter); this.name = name; this.layout = layout; this.ignoreExceptions = ignoreExceptions; } + public static int parseInt(final String s, final int defaultValue) { + try { + return Integers.parseInt(s, defaultValue); + } catch (final NumberFormatException e) { + LOGGER.error("Could not parse \"{}\" as an integer, using default value {}: {}", s, defaultValue, e); + return defaultValue; + } + } + /** * Handle an error with a message using the {@link ErrorHandler} configured for this Appender. + * * @param msg The message. */ public void error(final String msg) { @@ -89,6 +88,7 @@ public abstract class AbstractAppender extends AbstractFilterable /** * Handle an error with a message, exception, and a logging event, using the {@link ErrorHandler} configured for * this Appender. + * * @param msg The message. * @param event The LogEvent. * @param t The Throwable. @@ -99,6 +99,7 @@ public abstract class AbstractAppender extends AbstractFilterable /** * Handle an error with a message and an exception using the {@link ErrorHandler} configured for this Appender. + * * @param msg The message. * @param t The Throwable. */ @@ -108,6 +109,7 @@ public abstract class AbstractAppender extends AbstractFilterable /** * Returns the ErrorHandler, if any. + * * @return The ErrorHandler. */ @Override @@ -117,6 +119,7 @@ public abstract class AbstractAppender extends AbstractFilterable /** * Returns the Layout for the appender. + * * @return The Layout used to format the event. */ @Override @@ -126,6 +129,7 @@ public abstract class AbstractAppender extends AbstractFilterable /** * Returns the name of the Appender. + * * @return The name of the Appender. */ @Override @@ -146,6 +150,7 @@ public abstract class AbstractAppender extends AbstractFilterable /** * The handler must be set before the appender is started. + * * @param handler The ErrorHandler to use. */ @Override http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1236fac8/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java index 9df5936..3e09a61 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java @@ -35,13 +35,10 @@ public abstract class AbstractOutputStreamAppender<M extends OutputStreamManager private static final long serialVersionUID = 1L; /** - * Immediate flush means that the underlying writer or output stream - * will be flushed at the end of each append operation. Immediate - * flush is slower but ensures that each append request is actually - * written. If <code>immediateFlush</code> is set to - * {@code false}, then there is a good chance that the last few - * logs events are not actually written to persistent media if and - * when the application crashes. + * Immediate flush means that the underlying writer or output stream will be flushed at the end of each append + * operation. Immediate flush is slower but ensures that each append request is actually written. If + * <code>immediateFlush</code> is set to {@code false}, then there is a good chance that the last few logs events + * are not actually written to persistent media if and when the application crashes. */ protected final boolean immediateFlush; @@ -49,18 +46,17 @@ public abstract class AbstractOutputStreamAppender<M extends OutputStreamManager private final ReadWriteLock rwLock = new ReentrantReadWriteLock(); private final Lock readLock = rwLock.readLock(); - + /** - * Instantiate a WriterAppender and set the output destination to a - * new {@link java.io.OutputStreamWriter} initialized with <code>os</code> - * as its {@link java.io.OutputStream}. + * Instantiate a WriterAppender and set the output destination to a new {@link java.io.OutputStreamWriter} + * initialized with <code>os</code> as its {@link java.io.OutputStream}. + * * @param name The name of the Appender. * @param layout The layout to format the message. * @param manager The OutputStreamManager. */ - protected AbstractOutputStreamAppender(final String name, final Layout<? extends Serializable> layout, final Filter filter, - final boolean ignoreExceptions, final boolean immediateFlush, - final M manager) { + protected AbstractOutputStreamAppender(final String name, final Layout<? extends Serializable> layout, + final Filter filter, final boolean ignoreExceptions, final boolean immediateFlush, final M manager) { super(name, filter, layout, ignoreExceptions); this.manager = manager; this.immediateFlush = immediateFlush; @@ -98,8 +94,7 @@ public abstract class AbstractOutputStreamAppender<M extends OutputStreamManager * Most subclasses of <code>AbstractOutputStreamAppender</code> will need to override this method. * </p> * - * @param event - * The LogEvent. + * @param event The LogEvent. */ @Override public void append(final LogEvent event) { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1236fac8/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java index 4b6c740..0c0378c 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java @@ -41,10 +41,9 @@ import org.apache.logging.log4j.core.config.plugins.PluginFactory; import org.apache.logging.log4j.core.impl.Log4jLogEvent; /** - * Appends to one or more Appenders asynchronously. You can configure an - * AsyncAppender with one or more Appenders and an Appender to append to if the - * queue is full. The AsyncAppender does not allow a filter to be specified on - * the Appender references. + * Appends to one or more Appenders asynchronously. You can configure an AsyncAppender with one or more Appenders and an + * Appender to append to if the queue is full. The AsyncAppender does not allow a filter to be specified on the Appender + * references. */ @Plugin(name = "Async", category = "Core", elementType = "appender", printObject = true) public final class AsyncAppender extends AbstractAppender { @@ -53,6 +52,9 @@ public final class AsyncAppender extends AbstractAppender { private static final int DEFAULT_QUEUE_SIZE = 128; private static final String SHUTDOWN = "Shutdown"; + private static final AtomicLong THREAD_SEQUENCE = new AtomicLong(1); + private static ThreadLocal<Boolean> isAppenderThread = new ThreadLocal<>(); + private final BlockingQueue<Serializable> queue; private final int queueSize; private final boolean blocking; @@ -62,14 +64,10 @@ public final class AsyncAppender extends AbstractAppender { private final boolean includeLocation; private AppenderControl errorAppender; private AsyncThread thread; - private static final AtomicLong threadSequence = new AtomicLong(1); - private static ThreadLocal<Boolean> isAppenderThread = new ThreadLocal<>(); - private AsyncAppender(final String name, final Filter filter, final AppenderRef[] appenderRefs, - final String errorRef, final int queueSize, final boolean blocking, - final boolean ignoreExceptions, final Configuration config, - final boolean includeLocation) { + final String errorRef, final int queueSize, final boolean blocking, final boolean ignoreExceptions, + final Configuration config, final boolean includeLocation) { super(name, filter, null, ignoreExceptions); this.queue = new ArrayBlockingQueue<>(queueSize); this.queueSize = queueSize; @@ -127,8 +125,7 @@ public final class AsyncAppender extends AbstractAppender { /** * Actual writing occurs here. * - * @param logEvent - * The LogEvent. + * @param logEvent The LogEvent. */ @Override public void append(LogEvent logEvent) { @@ -171,7 +168,7 @@ public final class AsyncAppender extends AbstractAppender { appendSuccessful = queue.offer(serialized); if (!appendSuccessful) { LOGGER.warn("Interrupted while waiting for a free slot in the AsyncAppender LogEvent-queue {}", - getName()); + getName()); } // set the interrupted flag again. Thread.currentThread().interrupt(); @@ -190,6 +187,7 @@ public final class AsyncAppender extends AbstractAppender { /** * Create an AsyncAppender. + * * @param appenderRefs The Appenders to reference. * @param errorRef An optional Appender to write to if the queue is full or other errors occur. * @param blocking True if the Appender should wait when the queue is full. The default is true. @@ -199,7 +197,7 @@ public final class AsyncAppender extends AbstractAppender { * @param filter The Filter or null. * @param config The Configuration. * @param ignoreExceptions If {@code "true"} (default) exceptions encountered when appending events are logged; - * otherwise they are propagated to the caller. + * otherwise they are propagated to the caller. * @return The AsyncAppender. */ @PluginFactory @@ -209,8 +207,7 @@ public final class AsyncAppender extends AbstractAppender { @PluginAttribute(value = "bufferSize", defaultInt = DEFAULT_QUEUE_SIZE) final int size, @PluginAttribute("name") final String name, @PluginAttribute(value = "includeLocation", defaultBoolean = false) final boolean includeLocation, - @PluginElement("Filter") final Filter filter, - @PluginConfiguration final Configuration config, + @PluginElement("Filter") final Filter filter, @PluginConfiguration final Configuration config, @PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) final boolean ignoreExceptions) { if (name == null) { LOGGER.error("No name provided for AsyncAppender"); @@ -220,8 +217,8 @@ public final class AsyncAppender extends AbstractAppender { LOGGER.error("No appender references provided to AsyncAppender {}", name); } - return new AsyncAppender(name, filter, appenderRefs, errorRef, - size, blocking, ignoreExceptions, config, includeLocation); + return new AsyncAppender(name, filter, appenderRefs, errorRef, size, blocking, ignoreExceptions, config, + includeLocation); } /** @@ -237,7 +234,7 @@ public final class AsyncAppender extends AbstractAppender { this.appenders = appenders; this.queue = queue; setDaemon(true); - setName("AsyncAppenderThread" + threadSequence.getAndIncrement()); + setName("AsyncAppenderThread" + THREAD_SEQUENCE.getAndIncrement()); } @Override @@ -268,7 +265,7 @@ public final class AsyncAppender extends AbstractAppender { // Process any remaining items in the queue. LOGGER.trace("AsyncAppender.AsyncThread shutting down. Processing remaining {} queue events.", queue.size()); - int count= 0; + int count = 0; int ignored = 0; while (!queue.isEmpty()) { try { @@ -287,16 +284,14 @@ public final class AsyncAppender extends AbstractAppender { // Here we ignore interrupts and try to process all remaining events. } } - LOGGER.trace("AsyncAppender.AsyncThread stopped. Queue has {} events remaining. " + - "Processed {} and ignored {} events since shutdown started.", - queue.size(), count, ignored); + LOGGER.trace("AsyncAppender.AsyncThread stopped. Queue has {} events remaining. " + + "Processed {} and ignored {} events since shutdown started.", queue.size(), count, ignored); } /** - * Calls {@link AppenderControl#callAppender(LogEvent) callAppender} on - * all registered {@code AppenderControl} objects, and returns {@code true} - * if at least one appender call was successful, {@code false} otherwise. - * Any exceptions are silently ignored. + * Calls {@link AppenderControl#callAppender(LogEvent) callAppender} on all registered {@code AppenderControl} + * objects, and returns {@code true} if at least one appender call was successful, {@code false} otherwise. Any + * exceptions are silently ignored. * * @param event the event to forward to the registered appenders * @return {@code true} if at least one appender call succeeded, {@code false} otherwise @@ -323,8 +318,8 @@ public final class AsyncAppender extends AbstractAppender { } /** - * Returns the names of the appenders that this asyncAppender delegates to - * as an array of Strings. + * Returns the names of the appenders that this asyncAppender delegates to as an array of Strings. + * * @return the names of the sink appenders */ public String[] getAppenderRefStrings() { @@ -336,9 +331,9 @@ public final class AsyncAppender extends AbstractAppender { } /** - * Returns {@code true} if this AsyncAppender will take a snapshot of the stack with - * every log event to determine the class and method where the logging call - * was made. + * Returns {@code true} if this AsyncAppender will take a snapshot of the stack with every log event to determine + * the class and method where the logging call was made. + * * @return {@code true} if location is included with every event, {@code false} otherwise */ public boolean isIncludeLocation() { @@ -346,8 +341,9 @@ public final class AsyncAppender extends AbstractAppender { } /** - * Returns {@code true} if this AsyncAppender will block when the queue is full, - * or {@code false} if events are dropped when the queue is full. + * Returns {@code true} if this AsyncAppender will block when the queue is full, or {@code false} if events are + * dropped when the queue is full. + * * @return whether this AsyncAppender will block or drop events when the queue is full. */ public boolean isBlocking() { @@ -356,6 +352,7 @@ public final class AsyncAppender extends AbstractAppender { /** * Returns the name of the appender that any errors are logged to or {@code null}. + * * @return the name of the appender that any errors are logged to or {@code null} */ public String getErrorRef() { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1236fac8/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java index 4838443..8006401 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java @@ -39,14 +39,12 @@ import org.apache.logging.log4j.core.util.Loader; import org.apache.logging.log4j.util.PropertiesUtil; /** - * Appends log events to <code>System.out</code> or - * <code>System.err</code> using a layout specified by the user. The + * Appends log events to <code>System.out</code> or <code>System.err</code> using a layout specified by the user. The * default target is <code>System.out</code>. - * TODO accessing System.out or .err as a byte stream instead of a writer - * bypasses the JVM's knowledge of the proper encoding. (RG) Encoding - * is handled within the Layout. Typically, a Layout will generate a String - * and then call getBytes which may use a configured encoding or the system - * default. OTOH, a Writer cannot print byte streams. + * <p> + * TODO accessing System.out or .err as a byte stream instead of a writer bypasses the JVM's knowledge of the proper + * encoding. (RG) Encoding is handled within the Layout. Typically, a Layout will generate a String and then call + * getBytes which may use a configured encoding or the system default. OTOH, a Writer cannot print byte streams. */ @Plugin(name = "Console", category = "Core", elementType = "appender", printObject = true) public final class ConsoleAppender extends AbstractOutputStreamAppender<OutputStreamManager> { @@ -59,7 +57,7 @@ public final class ConsoleAppender extends AbstractOutputStreamAppender<OutputSt /** * Enumeration of console destinations. */ - public enum Target { + public static enum Target { /** Standard output. */ SYSTEM_OUT, /** Standard error output. */ @@ -67,25 +65,24 @@ public final class ConsoleAppender extends AbstractOutputStreamAppender<OutputSt } private ConsoleAppender(final String name, final Layout<? extends Serializable> layout, final Filter filter, - final OutputStreamManager manager, - final boolean ignoreExceptions) { + final OutputStreamManager manager, final boolean ignoreExceptions) { super(name, layout, filter, ignoreExceptions, true, manager); } /** * Creates a Console Appender. + * * @param layout The layout to use (required). * @param filter The Filter or null. * @param targetStr The target ("SYSTEM_OUT" or "SYSTEM_ERR"). The default is "SYSTEM_OUT". * @param follow If true will follow changes to the underlying output stream. * @param name The name of the Appender (required). - * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise - * they are propagated to the caller. + * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise they + * are propagated to the caller. * @return The ConsoleAppender. */ @PluginFactory - public static ConsoleAppender createAppender( - @PluginElement("Layout") Layout<? extends Serializable> layout, + public static ConsoleAppender createAppender(@PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filter") final Filter filter, @PluginAttribute(value = "target", defaultString = "SYSTEM_OUT") final String targetStr, @PluginAttribute("name") final String name, @@ -114,6 +111,9 @@ public final class ConsoleAppender extends AbstractOutputStreamAppender<OutputSt return new Builder(); } + /** + * Builds ConsoleAppender instances. + */ public static class Builder implements org.apache.logging.log4j.core.util.Builder<ConsoleAppender> { @PluginElement("Layout") @@ -137,33 +137,33 @@ public final class ConsoleAppender extends AbstractOutputStreamAppender<OutputSt @PluginBuilderAttribute private boolean ignoreExceptions = true; - public Builder setLayout(final Layout<? extends Serializable> layout) { - this.layout = layout; + public Builder setLayout(final Layout<? extends Serializable> aLayout) { + this.layout = aLayout; return this; } - public Builder setFilter(final Filter filter) { - this.filter = filter; + public Builder setFilter(final Filter aFilter) { + this.filter = aFilter; return this; } - public Builder setTarget(final Target target) { - this.target = target; + public Builder setTarget(final Target aTarget) { + this.target = aTarget; return this; } - public Builder setName(final String name) { - this.name = name; + public Builder setName(final String aName) { + this.name = aName; return this; } - public Builder setFollow(final boolean follow) { - this.follow = follow; + public Builder setFollow(final boolean shouldFollow) { + this.follow = shouldFollow; return this; } - public Builder setIgnoreExceptions(final boolean ignoreExceptions) { - this.ignoreExceptions = ignoreExceptions; + public Builder setIgnoreExceptions(final boolean shouldIgnoreExceptions) { + this.ignoreExceptions = shouldIgnoreExceptions; return this; } @@ -173,7 +173,8 @@ public final class ConsoleAppender extends AbstractOutputStreamAppender<OutputSt } } - private static OutputStreamManager getManager(final Target target, final boolean follow, final Layout<? extends Serializable> layout) { + private static OutputStreamManager getManager(final Target target, final boolean follow, + final Layout<? extends Serializable> layout) { final OutputStream os = getOutputStream(follow, target); final String managerName = target.name() + '.' + follow; return OutputStreamManager.getManager(managerName, new FactoryData(os, managerName, layout), factory); @@ -235,8 +236,7 @@ public final class ConsoleAppender extends AbstractOutputStreamAppender<OutputSt } @Override - public void write(final byte[] b, final int off, final int len) - throws IOException { + public void write(final byte[] b, final int off, final int len) throws IOException { System.err.write(b, off, len); } @@ -269,8 +269,7 @@ public final class ConsoleAppender extends AbstractOutputStreamAppender<OutputSt } @Override - public void write(final byte[] b, final int off, final int len) - throws IOException { + public void write(final byte[] b, final int off, final int len) throws IOException { System.out.write(b, off, len); } @@ -279,7 +278,7 @@ public final class ConsoleAppender extends AbstractOutputStreamAppender<OutputSt System.out.write(b); } } - + /** * A delegating OutputStream that does not close its delegate. */ @@ -307,8 +306,7 @@ public final class ConsoleAppender extends AbstractOutputStreamAppender<OutputSt } @Override - public void write(final byte[] b, final int off, final int len) - throws IOException { + public void write(final byte[] b, final int off, final int len) throws IOException { delegate.write(b, off, len); } @@ -328,6 +326,7 @@ public final class ConsoleAppender extends AbstractOutputStreamAppender<OutputSt /** * Constructor. + * * @param os The OutputStream. * @param type The name of the target. * @param layout A Serializable layout @@ -346,6 +345,7 @@ public final class ConsoleAppender extends AbstractOutputStreamAppender<OutputSt /** * Create an OutputStreamManager. + * * @param name The name of the entity to manage. * @param data The data required to create the entity. * @return The OutputStreamManager http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1236fac8/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java index 4998b7b..b6d2a20 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java @@ -41,23 +41,22 @@ import org.apache.logging.log4j.core.util.NullOutputStream; * memory and writes to this memory region. * <p> * - * @see <a - * href="http://www.codeproject.com/Tips/683614/Things-to-Know-about-Memory-Mapped-File-in-Java"> - * http://www.codeproject.com/Tips/683614/Things-to-Know-about-Memory-Mapped-File-in-Java</a> + * @see <a href="http://www.codeproject.com/Tips/683614/Things-to-Know-about-Memory-Mapped-File-in-Java"> + * http://www.codeproject.com/Tips/683614/Things-to-Know-about-Memory-Mapped-File-in-Java</a> * @see <a href="http://bugs.java.com/view_bug.do?bug_id=6893654">http://bugs.java.com/view_bug.do?bug_id=6893654</a> * @see <a href="http://bugs.java.com/view_bug.do?bug_id=4724038">http://bugs.java.com/view_bug.do?bug_id=4724038</a> * @see <a * href="http://stackoverflow.com/questions/9261316/memory-mapped-mappedbytebuffer-or-direct-bytebuffer-for-db-implementation"> - * http://stackoverflow.com/questions/9261316/memory-mapped-mappedbytebuffer-or-direct-bytebuffer-for-db-implementation</a> + * http://stackoverflow.com/questions/9261316/memory-mapped-mappedbytebuffer-or-direct-bytebuffer-for-db-implementation</a> * * @since 2.1 */ public class MemoryMappedFileManager extends OutputStreamManager { /** - * + * Default length of region to map. */ - private static final int MAX_REMAP_COUNT = 10; static final int DEFAULT_REGION_LENGTH = 32 * 1024 * 1024; + private static final int MAX_REMAP_COUNT = 10; private static final MemoryMappedFileManagerFactory FACTORY = new MemoryMappedFileManagerFactory(); private static final double NANOS_PER_MILLISEC = 1000.0 * 1000.0; @@ -104,8 +103,8 @@ public class MemoryMappedFileManager extends OutputStreamManager { return isEndOfBatch.get(); } - public void setEndOfBatch(final boolean isEndOfBatch) { - this.isEndOfBatch.set(Boolean.valueOf(isEndOfBatch)); + public void setEndOfBatch(final boolean endOfBatch) { + this.isEndOfBatch.set(Boolean.valueOf(endOfBatch)); } @Override @@ -293,7 +292,7 @@ public class MemoryMappedFileManager extends OutputStreamManager { /** * Factory to create a MemoryMappedFileManager. */ - private static class MemoryMappedFileManagerFactory + private static class MemoryMappedFileManagerFactory implements ManagerFactory<MemoryMappedFileManager, FactoryData> { /** http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1236fac8/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java index 1110cbc..4d667d9 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java @@ -80,8 +80,8 @@ public class RandomAccessFileManager extends OutputStreamManager { return isEndOfBatch.get(); } - public void setEndOfBatch(final boolean isEndOfBatch) { - this.isEndOfBatch.set(Boolean.valueOf(isEndOfBatch)); + public void setEndOfBatch(final boolean endOfBatch) { + this.isEndOfBatch.set(Boolean.valueOf(endOfBatch)); } @Override http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1236fac8/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java index d538a63..2521ae6 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java @@ -105,7 +105,8 @@ public final class RollingFileAppender extends AbstractOutputStreamAppender<Roll } /** - * Returns the triggering policy + * Returns the triggering policy. + * @param <T> TriggeringPolicy type * @return The TriggeringPolicy */ public <T extends TriggeringPolicy> T getTriggeringPolicy() {
