"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java" between
apache-log4j-2.11.1-src.tar.gz and apache-log4j-2.11.2-src.tar.gz

About: Apache Log4j 2 is a logging library for Java. Source distribution (Java).

AsyncLoggerConfig.java  (apache-log4j-2.11.1-src):AsyncLoggerConfig.java  (apache-log4j-2.11.2-src)
skipping to change at line 75 skipping to change at line 75
* For best performance, use AsyncLoggerConfig with the RandomAccessFileAppender or * For best performance, use AsyncLoggerConfig with the RandomAccessFileAppender or
* RollingRandomAccessFileAppender, with immediateFlush=false. These appenders h ave * RollingRandomAccessFileAppender, with immediateFlush=false. These appenders h ave
* built-in support for the batching mechanism used by the Disruptor library, * built-in support for the batching mechanism used by the Disruptor library,
* and they will flush to disk at the end of each batch. This means that even * and they will flush to disk at the end of each batch. This means that even
* with immediateFlush=false, there will never be any items left in the buffer; * with immediateFlush=false, there will never be any items left in the buffer;
* all log events will all be written to disk in a very efficient manner. * all log events will all be written to disk in a very efficient manner.
*/ */
@Plugin(name = "asyncLogger", category = Node.CATEGORY, printObject = true) @Plugin(name = "asyncLogger", category = Node.CATEGORY, printObject = true)
public class AsyncLoggerConfig extends LoggerConfig { public class AsyncLoggerConfig extends LoggerConfig {
private static final ThreadLocal<Boolean> ASYNC_LOGGER_ENTERED = new ThreadL private static final ThreadLocal<Boolean> ASYNC_LOGGER_ENTERED = new ThreadL
ocal<>(); ocal<Boolean>() {
@Override
protected Boolean initialValue() {
return Boolean.FALSE;
}
};
private final AsyncLoggerConfigDelegate delegate; private final AsyncLoggerConfigDelegate delegate;
protected AsyncLoggerConfig(final String name, protected AsyncLoggerConfig(final String name,
final List<AppenderRef> appenders, final Filter filter, final List<AppenderRef> appenders, final Filter filter,
final Level level, final boolean additive, final Level level, final boolean additive,
final Property[] properties, final Configuration config, final Property[] properties, final Configuration config,
final boolean includeLocation) { final boolean includeLocation) {
super(name, appenders, filter, level, additive, properties, config, super(name, appenders, filter, level, additive, properties, config,
includeLocation); includeLocation);
delegate = config.getAsyncLoggerConfigDelegate(); delegate = config.getAsyncLoggerConfigDelegate();
delegate.setLogEventFactory(getLogEventFactory()); delegate.setLogEventFactory(getLogEventFactory());
} }
@Override
protected void log(final LogEvent event, final LoggerConfigPredicate predica te) { protected void log(final LogEvent event, final LoggerConfigPredicate predica te) {
// See LOG4J2-2301 // See LOG4J2-2301
if (predicate == LoggerConfigPredicate.ALL && if (predicate == LoggerConfigPredicate.ALL &&
ASYNC_LOGGER_ENTERED.get() == null && ASYNC_LOGGER_ENTERED.get() == Boolean.FALSE &&
// Optimization: AsyncLoggerConfig is identical to LoggerConfig // Optimization: AsyncLoggerConfig is identical to LoggerConfig
// when no appenders are present. Avoid splitting for synchronou s // when no appenders are present. Avoid splitting for synchronou s
// and asynchronous execution paths until encountering an // and asynchronous execution paths until encountering an
// AsyncLoggerConfig with appenders. // AsyncLoggerConfig with appenders.
hasAppenders()) { hasAppenders()) {
// This is the first AsnycLoggerConfig encountered by this LogEvent // This is the first AsnycLoggerConfig encountered by this LogEvent
ASYNC_LOGGER_ENTERED.set(Boolean.TRUE); ASYNC_LOGGER_ENTERED.set(Boolean.TRUE);
try { try {
// Detect the first time we encounter an AsyncLoggerConfig. We m ust log // Detect the first time we encounter an AsyncLoggerConfig. We m ust log
// to all non-async loggers first. // to all non-async loggers first.
super.log(event, LoggerConfigPredicate.SYNCHRONOUS_ONLY); super.log(event, LoggerConfigPredicate.SYNCHRONOUS_ONLY);
// Then pass the event to the background thread where // Then pass the event to the background thread where
// all async logging is executed. It is important this // all async logging is executed. It is important this
// happens at most once and after all synchronous loggers // happens at most once and after all synchronous loggers
// have been invoked, because we lose parameter references // have been invoked, because we lose parameter references
// from reusable messages. // from reusable messages.
logToAsyncDelegate(event); logToAsyncDelegate(event);
} finally { } finally {
ASYNC_LOGGER_ENTERED.remove(); ASYNC_LOGGER_ENTERED.set(Boolean.FALSE);
} }
} else { } else {
super.log(event, predicate); super.log(event, predicate);
} }
} }
@Override @Override
protected void callAppenders(final LogEvent event) { protected void callAppenders(final LogEvent event) {
super.callAppenders(event); super.callAppenders(event);
} }
private void logToAsyncDelegate(LogEvent event) { private void logToAsyncDelegate(final LogEvent event) {
if (!isFiltered(event)) { if (!isFiltered(event)) {
// Passes on the event to a separate thread that will call // Passes on the event to a separate thread that will call
// asyncCallAppenders(LogEvent). // asyncCallAppenders(LogEvent).
populateLazilyInitializedFields(event); populateLazilyInitializedFields(event);
if (!delegate.tryEnqueue(event, this)) { if (!delegate.tryEnqueue(event, this)) {
handleQueueFull(event); handleQueueFull(event);
} }
} }
} }
 End of changes. 5 change blocks. 
5 lines changed or deleted 12 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)