http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java index f687ff4..5d8d4fd 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java @@ -92,8 +92,8 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage, CharSequen public void setValues(final AsyncLogger anAsyncLogger, final String aLoggerName, final Marker aMarker, final String theFqcn, final Level aLevel, final Message msg, final Throwable aThrowable, - final Map<String, String> aMap, final ContextStack aContextStack, long threadId, - final String threadName, int threadPriority, final StackTraceElement aLocation, final long aCurrentTimeMillis, final long aNanoTime) { + final Map<String, String> aMap, final ContextStack aContextStack, final long threadId, + final String threadName, final int threadPriority, final StackTraceElement aLocation, final long aCurrentTimeMillis, final long aNanoTime) { this.threadPriority = threadPriority; this.threadId = threadId; this.currentTimeMillis = aCurrentTimeMillis; @@ -283,12 +283,12 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage, CharSequen } @Override - public char charAt(int index) { + public char charAt(final int index) { return messageText.charAt(index); } @Override - public CharSequence subSequence(int start, int end) { + public CharSequence subSequence(final int start, final int end) { return messageText.subSequence(start, end); } @@ -439,7 +439,7 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage, CharSequen * Initializes the specified {@code Log4jLogEvent.Builder} from this {@code RingBufferLogEvent}. * @param builder the builder whose fields to populate */ - public void initializeBuilder(Log4jLogEvent.Builder builder) { + public void initializeBuilder(final Log4jLogEvent.Builder builder) { builder.setContextMap(contextMap) // .setContextStack(contextStack) // .setEndOfBatch(endOfBatch) //
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/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 316381a..3562ce4 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 @@ -155,7 +155,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement return scriptManager; } - public void setScriptManager(ScriptManager scriptManager) { + public void setScriptManager(final ScriptManager scriptManager) { this.scriptManager = scriptManager; } @@ -163,7 +163,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement return pluginManager; } - public void setPluginManager(PluginManager pluginManager) { + public void setPluginManager(final PluginManager pluginManager) { this.pluginManager = pluginManager; } @@ -434,7 +434,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement componentMap.putIfAbsent(componentName, obj); } - protected void preConfigure(Node node) { + protected void preConfigure(final Node node) { try { for (final Node child : node.getChildren()) { if (child.getType() == null) { @@ -655,7 +655,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement * .core.config.LoggerConfig) */ @Override - public ReliabilityStrategy getReliabilityStrategy(LoggerConfig loggerConfig) { + public ReliabilityStrategy getReliabilityStrategy(final LoggerConfig loggerConfig) { return ReliabilityStrategyFactory.getReliabilityStrategy(loggerConfig); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/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 96467f1..ccc35d0 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 @@ -1,175 +1,175 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ - -package org.apache.logging.log4j.core.config; - -import java.util.Objects; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.locks.Condition; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.message.Message; -import org.apache.logging.log4j.util.Supplier; - -/** - * ReliabilityStrategy that counts the number of threads that have started to log an event but have not completed yet, - * and waits for these threads to finish before allowing the appenders to be stopped. - */ -public class AwaitCompletionReliabilityStrategy implements ReliabilityStrategy { - private static final int MAX_RETRIES = 3; - private final AtomicInteger counter = new AtomicInteger(); - private final AtomicBoolean shutdown = new AtomicBoolean(false); - private final Lock shutdownLock = new ReentrantLock(); - private final Condition noLogEvents = shutdownLock.newCondition(); // should only be used when shutdown == true - private final LoggerConfig loggerConfig; - - public AwaitCompletionReliabilityStrategy(final LoggerConfig loggerConfig) { - 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) - */ - @Override - public void log(final Supplier<LoggerConfig> reconfigured, final String loggerName, final String fqcn, - final Marker marker, final Level level, final Message data, final Throwable t) { - - final LoggerConfig config = getActiveLoggerConfig(reconfigured); - try { - config.log(loggerName, fqcn, marker, level, data, t); - } finally { - config.getReliabilityStrategy().afterLogEvent(); - } - } - - /* - * (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) { - final LoggerConfig config = getActiveLoggerConfig(reconfigured); - try { - config.log(event); - } finally { - config.getReliabilityStrategy().afterLogEvent(); - } - } - - /* - * (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) { - LoggerConfig result = this.loggerConfig; - if (!beforeLogEvent()) { - result = next.get(); - return result.getReliabilityStrategy().getActiveLoggerConfig(next); - } - return result; - } - - private boolean beforeLogEvent() { - return counter.incrementAndGet() > 0; - } - - @Override - public void afterLogEvent() { - if (counter.decrementAndGet() == 0 && shutdown.get()) { - signalCompletionIfShutdown(); - } - } - - private void signalCompletionIfShutdown() { - final Lock lock = shutdownLock; - lock.lock(); - try { - noLogEvents.signalAll(); - } finally { - lock.unlock(); - } - } - - /* - * (non-Javadoc) - * - * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopAppenders() - */ - @Override - public void beforeStopAppenders() { - waitForCompletion(); - } - - /** - * Waits for all log events to complete before returning. - */ - private void waitForCompletion() { - shutdownLock.lock(); - try { - if (shutdown.compareAndSet(false, true)) { - int retries = 0; - // repeat while counter is non-zero - while (!counter.compareAndSet(0, Integer.MIN_VALUE)) { - - // counter was non-zero - if (counter.get() < 0) { // this should not happen - return; // but if it does, we are already done - } - // counter greater than zero, wait for afterLogEvent to decrease count - try { - noLogEvents.await(retries + 1, TimeUnit.SECONDS); - } catch (final InterruptedException ie) { - if (++retries > MAX_RETRIES) { - break; - } - } - } - } - } finally { - shutdownLock.unlock(); - } - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopConfiguration(org.apache.logging.log4j.core - * .config.Configuration) - */ - @Override - public void beforeStopConfiguration(Configuration configuration) { - // no action - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ + +package org.apache.logging.log4j.core.config; + +import java.util.Objects; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.util.Supplier; + +/** + * ReliabilityStrategy that counts the number of threads that have started to log an event but have not completed yet, + * and waits for these threads to finish before allowing the appenders to be stopped. + */ +public class AwaitCompletionReliabilityStrategy implements ReliabilityStrategy { + private static final int MAX_RETRIES = 3; + private final AtomicInteger counter = new AtomicInteger(); + private final AtomicBoolean shutdown = new AtomicBoolean(false); + private final Lock shutdownLock = new ReentrantLock(); + private final Condition noLogEvents = shutdownLock.newCondition(); // should only be used when shutdown == true + private final LoggerConfig loggerConfig; + + public AwaitCompletionReliabilityStrategy(final LoggerConfig loggerConfig) { + 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) + */ + @Override + public void log(final Supplier<LoggerConfig> reconfigured, final String loggerName, final String fqcn, + final Marker marker, final Level level, final Message data, final Throwable t) { + + final LoggerConfig config = getActiveLoggerConfig(reconfigured); + try { + config.log(loggerName, fqcn, marker, level, data, t); + } finally { + config.getReliabilityStrategy().afterLogEvent(); + } + } + + /* + * (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) { + final LoggerConfig config = getActiveLoggerConfig(reconfigured); + try { + config.log(event); + } finally { + config.getReliabilityStrategy().afterLogEvent(); + } + } + + /* + * (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) { + LoggerConfig result = this.loggerConfig; + if (!beforeLogEvent()) { + result = next.get(); + return result.getReliabilityStrategy().getActiveLoggerConfig(next); + } + return result; + } + + private boolean beforeLogEvent() { + return counter.incrementAndGet() > 0; + } + + @Override + public void afterLogEvent() { + if (counter.decrementAndGet() == 0 && shutdown.get()) { + signalCompletionIfShutdown(); + } + } + + private void signalCompletionIfShutdown() { + final Lock lock = shutdownLock; + lock.lock(); + try { + noLogEvents.signalAll(); + } finally { + lock.unlock(); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopAppenders() + */ + @Override + public void beforeStopAppenders() { + waitForCompletion(); + } + + /** + * Waits for all log events to complete before returning. + */ + private void waitForCompletion() { + shutdownLock.lock(); + try { + if (shutdown.compareAndSet(false, true)) { + int retries = 0; + // repeat while counter is non-zero + while (!counter.compareAndSet(0, Integer.MIN_VALUE)) { + + // counter was non-zero + if (counter.get() < 0) { // this should not happen + return; // but if it does, we are already done + } + // counter greater than zero, wait for afterLogEvent to decrease count + try { + noLogEvents.await(retries + 1, TimeUnit.SECONDS); + } catch (final InterruptedException ie) { + if (++retries > MAX_RETRIES) { + break; + } + } + } + } + } finally { + shutdownLock.unlock(); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopConfiguration(org.apache.logging.log4j.core + * .config.Configuration) + */ + @Override + public void beforeStopConfiguration(final Configuration configuration) { + // no action + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/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 5e0456c..806a1f3 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 @@ -1,123 +1,123 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ - -package org.apache.logging.log4j.core.config; - -import java.util.Objects; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.message.Message; -import org.apache.logging.log4j.status.StatusLogger; -import org.apache.logging.log4j.util.PropertiesUtil; -import org.apache.logging.log4j.util.Supplier; - -/** - * Reliability strategy that sleeps unconditionally for some time before allowing a Configuration to be stopped. - */ -public class AwaitUnconditionallyReliabilityStrategy implements ReliabilityStrategy { - - private static final long DEFAULT_SLEEP_MILLIS = 5000; // 5 seconds - private static final long SLEEP_MILLIS = sleepMillis(); - private final LoggerConfig loggerConfig; - - 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); - } - - /* - * (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(Supplier<LoggerConfig> reconfigured, String loggerName, String fqcn, Marker marker, Level level, - Message data, Throwable t) { - loggerConfig.log(loggerName, fqcn, marker, level, data, t); - } - - /* - * (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(Supplier<LoggerConfig> reconfigured, LogEvent event) { - loggerConfig.log(event); - } - - /* - * (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(Supplier<LoggerConfig> next) { - return this.loggerConfig; - } - - /* - * (non-Javadoc) - * - * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#afterLogEvent() - */ - @Override - public void afterLogEvent() { - // no action - } - - /* - * (non-Javadoc) - * - * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopAppenders() - */ - @Override - public void beforeStopAppenders() { - // no action - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopConfiguration(org.apache.logging.log4j.core - * .config.Configuration) - */ - @Override - public void beforeStopConfiguration(Configuration configuration) { - // only sleep once per configuration stop - if (loggerConfig == configuration.getRootLogger()) { - try { - Thread.sleep(SLEEP_MILLIS); - } catch (InterruptedException e) { - StatusLogger.getLogger().warn("Sleep before stop configuration was interrupted."); - } - } - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ + +package org.apache.logging.log4j.core.config; + +import java.util.Objects; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.status.StatusLogger; +import org.apache.logging.log4j.util.PropertiesUtil; +import org.apache.logging.log4j.util.Supplier; + +/** + * Reliability strategy that sleeps unconditionally for some time before allowing a Configuration to be stopped. + */ +public class AwaitUnconditionallyReliabilityStrategy implements ReliabilityStrategy { + + private static final long DEFAULT_SLEEP_MILLIS = 5000; // 5 seconds + private static final long SLEEP_MILLIS = sleepMillis(); + private final LoggerConfig loggerConfig; + + 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); + } + + /* + * (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, final Marker marker, final Level level, + final Message data, final Throwable t) { + loggerConfig.log(loggerName, fqcn, marker, level, data, t); + } + + /* + * (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) { + loggerConfig.log(event); + } + + /* + * (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) { + return this.loggerConfig; + } + + /* + * (non-Javadoc) + * + * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#afterLogEvent() + */ + @Override + public void afterLogEvent() { + // no action + } + + /* + * (non-Javadoc) + * + * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopAppenders() + */ + @Override + public void beforeStopAppenders() { + // no action + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopConfiguration(org.apache.logging.log4j.core + * .config.Configuration) + */ + @Override + public void beforeStopConfiguration(final Configuration configuration) { + // only sleep once per configuration stop + if (loggerConfig == configuration.getRootLogger()) { + try { + Thread.sleep(SLEEP_MILLIS); + } catch (InterruptedException e) { + StatusLogger.getLogger().warn("Sleep before stop configuration was interrupted."); + } + } + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java index 32cfe90..05c5823 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java @@ -458,7 +458,7 @@ public abstract class ConfigurationFactory extends ConfigurationBuilderFactory { return new DefaultConfiguration(); } - private Configuration getConfiguration(String configLocationStr) { + private Configuration getConfiguration(final String configLocationStr) { ConfigurationSource source = null; try { source = getInputFromUri(NetUtils.toURI(configLocationStr)); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java index ed2c277..50b8194 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java @@ -91,7 +91,7 @@ public class ConfigurationScheduler extends AbstractLifeCycle { * @return a ScheduledFuture that can be used to extract result or cancel. * */ - public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) { + public <V> ScheduledFuture<V> schedule(final Callable<V> callable, final long delay, final TimeUnit unit) { return executorService.schedule(callable, delay, unit); } @@ -103,7 +103,7 @@ public class ConfigurationScheduler extends AbstractLifeCycle { * @return a ScheduledFuture representing pending completion of the task and whose get() method will return null * upon completion. */ - public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { + public ScheduledFuture<?> schedule(final Runnable command, final long delay, final TimeUnit unit) { return executorService.schedule(command, delay, unit); } @@ -114,7 +114,7 @@ public class ConfigurationScheduler extends AbstractLifeCycle { * @param command The Runnable to run, * @return a ScheduledFuture representing the next time the command will run. */ - public CronScheduledFuture<?> scheduleWithCron(CronExpression cronExpression, Runnable command) { + public CronScheduledFuture<?> scheduleWithCron(final CronExpression cronExpression, final Runnable command) { CronRunnable runnable = new CronRunnable(command, cronExpression); ScheduledFuture<?> future = schedule(runnable, nextFireInterval(cronExpression), TimeUnit.MILLISECONDS); CronScheduledFuture<?> cronScheduledFuture = new CronScheduledFuture<>(future); @@ -134,7 +134,7 @@ public class ConfigurationScheduler extends AbstractLifeCycle { * @return a ScheduledFuture representing pending completion of the task, and whose get() method will throw an * exception upon cancellation */ - public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) { + public ScheduledFuture<?> scheduleAtFixedRate(final Runnable command, final long initialDelay, final long period, final TimeUnit unit) { return executorService.scheduleAtFixedRate(command, initialDelay, period, unit); } @@ -148,7 +148,7 @@ public class ConfigurationScheduler extends AbstractLifeCycle { * @return a ScheduledFuture representing pending completion of the task, and whose get() method will throw an * exception upon cancellation */ - public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) { + public ScheduledFuture<?> scheduleWithFixedDelay(final Runnable command, final long initialDelay, final long delay, final TimeUnit unit) { return executorService.scheduleWithFixedDelay(command, initialDelay, delay, unit); } @@ -158,12 +158,12 @@ public class ConfigurationScheduler extends AbstractLifeCycle { private final Runnable runnable; private CronScheduledFuture<?> scheduledFuture; - public CronRunnable(Runnable runnable, CronExpression cronExpression) { + public CronRunnable(final Runnable runnable, final CronExpression cronExpression) { this.cronExpression = cronExpression; this.runnable = runnable; } - public void setScheduledFuture(CronScheduledFuture<?> future) { + public void setScheduledFuture(final CronScheduledFuture<?> future) { this.scheduledFuture = future; } @@ -180,7 +180,7 @@ public class ConfigurationScheduler extends AbstractLifeCycle { } } - private long nextFireInterval(CronExpression cronExpression) { + private long nextFireInterval(final CronExpression cronExpression) { Date now = new Date(); Date fireDate = cronExpression.getNextValidTimeAfter(now); return fireDate.getTime() - now.getTime(); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfiguratonFileWatcher.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfiguratonFileWatcher.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfiguratonFileWatcher.java index 82d06ab..ceb6b57 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfiguratonFileWatcher.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfiguratonFileWatcher.java @@ -30,7 +30,7 @@ public class ConfiguratonFileWatcher implements FileWatcher { private final Reconfigurable reconfigurable; private final List<ConfigurationListener> listeners; - public ConfiguratonFileWatcher(Reconfigurable reconfigurable, final List<ConfigurationListener> listeners) { + public ConfiguratonFileWatcher(final Reconfigurable reconfigurable, final List<ConfigurationListener> listeners) { this.reconfigurable = reconfigurable; this.listeners = listeners; } @@ -41,7 +41,7 @@ public class ConfiguratonFileWatcher implements FileWatcher { @Override - public void fileModified(File file) { + public void fileModified(final File file) { for (final ConfigurationListener listener : listeners) { final Thread thread = new Log4jThread(new ReconfigurationWorker(listener, reconfigurable)); thread.setDaemon(true); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java index 147c20f..f152ac3 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java @@ -1,344 +1,344 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.config; - -import java.net.URI; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.core.impl.Log4jContextFactory; -import org.apache.logging.log4j.core.util.NetUtils; -import org.apache.logging.log4j.spi.LoggerContextFactory; -import org.apache.logging.log4j.status.StatusLogger; -import org.apache.logging.log4j.util.Strings; - -/** - * Initializes and configure the Logging system. This class provides several ways to construct a LoggerContext using - * the location of a configuration file, a context name, and various optional parameters. - */ -public final class Configurator { - - private static final String FQCN = Configurator.class.getName(); - - private static final Logger LOGGER = StatusLogger.getLogger(); - - private static Log4jContextFactory getFactory() { - final LoggerContextFactory factory = LogManager.getFactory(); - if (factory instanceof Log4jContextFactory) { - return (Log4jContextFactory) factory; - } else if (factory != null) { - LOGGER.error("LogManager returned an instance of {} which does not implement {}. Unable to initialize Log4j.", - factory.getClass().getName(), Log4jContextFactory.class.getName()); - return null; - } else { - LOGGER.fatal("LogManager did not return a LoggerContextFactory. This indicates something has gone terribly wrong!"); - return null; - } - } - - /** - * Initializes the Logging Context. - * @param loader The ClassLoader for the Context (or null). - * @param source The InputSource for the configuration. - * @return The LoggerContext. - */ - public static LoggerContext initialize(final ClassLoader loader, - final ConfigurationSource source) { - return initialize(loader, source, null); - } - - /** - * Initializes the Logging Context. - * @param loader The ClassLoader for the Context (or null). - * @param source The InputSource for the configuration. - * @param externalContext The external context to be attached to the LoggerContext. - * @return The LoggerContext. - */ - - public static LoggerContext initialize(final ClassLoader loader, - final ConfigurationSource source, - final Object externalContext) - { - - try { - final Log4jContextFactory factory = getFactory(); - return factory == null ? null : - factory.getContext(FQCN, loader, externalContext, false, source); - } catch (final Exception ex) { - LOGGER.error("There was a problem obtaining a LoggerContext using the configuration source [{}]", source, ex); - } - return null; - } - - /** - * Initializes the Logging Context. - * @param name The Context name. - * @param loader The ClassLoader for the Context (or null). - * @param configLocation The configuration for the logging context. - * @return The LoggerContext or null if an error occurred (check the status logger). - */ - public static LoggerContext initialize(final String name, final ClassLoader loader, final String configLocation) { - return initialize(name, loader, configLocation, null); - - } - - /** - * Initializes the Logging Context. - * @param name The Context name. - * @param loader The ClassLoader for the Context (or null). - * @param configLocation The configuration for the logging context (or null, or blank). - * @param externalContext The external context to be attached to the LoggerContext - * @return The LoggerContext or null if an error occurred (check the status logger). - */ - public static LoggerContext initialize(final String name, final ClassLoader loader, final String configLocation, - final Object externalContext) { - if (Strings.isBlank(configLocation)) { - return initialize(name, loader, (URI) null, externalContext); - } - if (configLocation.contains(",")) { - String[] parts = configLocation.split(","); - String scheme = null; - List<URI> uris = new ArrayList<>(parts.length); - for (String part : parts) { - URI uri = NetUtils.toURI(scheme != null ? scheme + ":" + part.trim() : part.trim()); - if (scheme == null && uri.getScheme() != null) { - scheme = uri.getScheme(); - } - uris.add(uri); - } - return initialize(name, loader, uris, externalContext); - } else { - return initialize(name, loader, NetUtils.toURI(configLocation), externalContext); - } - } - - /** - * Initializes the Logging Context. - * @param name The Context name. - * @param loader The ClassLoader for the Context (or null). - * @param configLocation The configuration for the logging context. - * @return The LoggerContext. - */ - public static LoggerContext initialize(final String name, final ClassLoader loader, final URI configLocation) { - return initialize(name, loader, configLocation, null); - } - - /** - * Initializes the Logging Context. - * @param name The Context name. - * @param loader The ClassLoader for the Context (or null). - * @param configLocation The configuration for the logging context (or null). - * @param externalContext The external context to be attached to the LoggerContext - * @return The LoggerContext. - */ - public static LoggerContext initialize(final String name, final ClassLoader loader, final URI configLocation, - final Object externalContext) { - - try { - final Log4jContextFactory factory = getFactory(); - return factory == null ? null : - factory.getContext(FQCN, loader, externalContext, false, configLocation, name); - } catch (final Exception ex) { - LOGGER.error("There was a problem initializing the LoggerContext [{}] using configuration at [{}].", - name, configLocation, ex); - } - return null; - } - - public static LoggerContext initialize(final String name, final ClassLoader loader, final List<URI> configLocations, - final Object externalContext) { - try { - final Log4jContextFactory factory = getFactory(); - return factory == null ? - null : - factory.getContext(FQCN, loader, externalContext, false, configLocations, name); - } catch (final Exception ex) { - LOGGER.error("There was a problem initializing the LoggerContext [{}] using configurations at [{}].", name, - configLocations, ex); - } - return null; - } - - /** - * Initializes the Logging Context. - * @param name The Context name. - * @param configLocation The configuration for the logging context. - * @return The LoggerContext or null if an error occurred (check the status logger). - */ - public static LoggerContext initialize(final String name, final String configLocation) { - return initialize(name, null, configLocation); - } - - /** - * Initializes the Logging Context. - * @param configuration The Configuration. - * @return The LoggerContext. - */ - public static LoggerContext initialize(Configuration configuration) { - return initialize(null, configuration, null); - } - - /** - * Initializes the Logging Context. - * @param loader The ClassLoader. - * @param configuration The Configuration. - * @return The LoggerContext. - */ - public static LoggerContext initialize(final ClassLoader loader, Configuration configuration) { - return initialize(loader, configuration, null); - } - - /** - * Initializes the Logging Context. - * @param loader The ClassLoader. - * @param configuration The Configuration. - * @param externalContext - The external context to be attached to the LoggerContext. - * @return The LoggerContext. - */ - public static LoggerContext initialize(final ClassLoader loader, Configuration configuration, final Object externalContext) { - try { - final Log4jContextFactory factory = getFactory(); - return factory == null ? null : - factory.getContext(FQCN, loader, externalContext, false, configuration); - } catch (final Exception ex) { - LOGGER.error("There was a problem initializing the LoggerContext using configuration {}", - configuration.getName(), ex); - } - return null; - } - - /** - * Sets the levels of <code>parentLogger</code> and all 'child' loggers to the given <code>level</code>. - * @param parentLogger the parent logger - * @param level the new level - */ - public static void setAllLevels(final String parentLogger, final Level level) { - // 1) get logger config - // 2) if exact match, use it, if not, create it. - // 3) set level on logger config - // 4) update child logger configs with level - // 5) update loggers - final LoggerContext loggerContext = LoggerContext.getContext(false); - final Configuration config = loggerContext.getConfiguration(); - boolean set = setLevel(parentLogger, level, config); - for (final Map.Entry<String, LoggerConfig> entry : config.getLoggers().entrySet()) { - if (entry.getKey().startsWith(parentLogger)) { - set |= setLevel(entry.getValue(), level); - } - } - if (set) { - loggerContext.updateLoggers(); - } - } - - private static boolean setLevel(final LoggerConfig loggerConfig, final Level level) { - final boolean set = !loggerConfig.getLevel().equals(level); - if (set) { - loggerConfig.setLevel(level); - } - return set; - } - - /** - * Sets logger levels. - * - * @param levelMap - * a levelMap where keys are level names and values are new - * Levels. - */ - public static void setLevel(final Map<String, Level> levelMap) { - final LoggerContext loggerContext = LoggerContext.getContext(false); - final Configuration config = loggerContext.getConfiguration(); - boolean set = false; - for (final Map.Entry<String, Level> entry : levelMap.entrySet()) { - final String loggerName = entry.getKey(); - final Level level = entry.getValue(); - set |= setLevel(loggerName, level, config); - } - if (set) { - loggerContext.updateLoggers(); - } - } - - /** - * Sets a logger's level. - * - * @param loggerName - * the logger name - * @param level - * the new level - */ - public static void setLevel(final String loggerName, final Level level) { - final LoggerContext loggerContext = LoggerContext.getContext(false); - if (Strings.isEmpty(loggerName)) { - setRootLevel(level); - } else { - if (setLevel(loggerName, level, loggerContext.getConfiguration())) { - loggerContext.updateLoggers(); - } - } - } - - private static boolean setLevel(final String loggerName, final Level level, final Configuration config) { - boolean set; - LoggerConfig loggerConfig = config.getLoggerConfig(loggerName); - if (!loggerName.equals(loggerConfig.getName())) { - // TODO Should additivity be inherited? - loggerConfig = new LoggerConfig(loggerName, level, true); - config.addLogger(loggerName, loggerConfig); - loggerConfig.setLevel(level); - set = true; - } else { - set = setLevel(loggerConfig, level); - } - return set; - } - - /** - * Sets the root logger's level. - * - * @param level - * the new level - */ - public static void setRootLevel(final Level level) { - final LoggerContext loggerContext = LoggerContext.getContext(false); - final LoggerConfig loggerConfig = loggerContext.getConfiguration().getRootLogger(); - if (!loggerConfig.getLevel().equals(level)) { - loggerConfig.setLevel(level); - loggerContext.updateLoggers(); - } - } - - /** - * Shuts down the given logging context. - * @param ctx the logging context to shut down, may be null. - */ - public static void shutdown(final LoggerContext ctx) { - if (ctx != null) { - ctx.stop(); - } - } - - private Configurator() { - // empty - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.config; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.impl.Log4jContextFactory; +import org.apache.logging.log4j.core.util.NetUtils; +import org.apache.logging.log4j.spi.LoggerContextFactory; +import org.apache.logging.log4j.status.StatusLogger; +import org.apache.logging.log4j.util.Strings; + +/** + * Initializes and configure the Logging system. This class provides several ways to construct a LoggerContext using + * the location of a configuration file, a context name, and various optional parameters. + */ +public final class Configurator { + + private static final String FQCN = Configurator.class.getName(); + + private static final Logger LOGGER = StatusLogger.getLogger(); + + private static Log4jContextFactory getFactory() { + final LoggerContextFactory factory = LogManager.getFactory(); + if (factory instanceof Log4jContextFactory) { + return (Log4jContextFactory) factory; + } else if (factory != null) { + LOGGER.error("LogManager returned an instance of {} which does not implement {}. Unable to initialize Log4j.", + factory.getClass().getName(), Log4jContextFactory.class.getName()); + return null; + } else { + LOGGER.fatal("LogManager did not return a LoggerContextFactory. This indicates something has gone terribly wrong!"); + return null; + } + } + + /** + * Initializes the Logging Context. + * @param loader The ClassLoader for the Context (or null). + * @param source The InputSource for the configuration. + * @return The LoggerContext. + */ + public static LoggerContext initialize(final ClassLoader loader, + final ConfigurationSource source) { + return initialize(loader, source, null); + } + + /** + * Initializes the Logging Context. + * @param loader The ClassLoader for the Context (or null). + * @param source The InputSource for the configuration. + * @param externalContext The external context to be attached to the LoggerContext. + * @return The LoggerContext. + */ + + public static LoggerContext initialize(final ClassLoader loader, + final ConfigurationSource source, + final Object externalContext) + { + + try { + final Log4jContextFactory factory = getFactory(); + return factory == null ? null : + factory.getContext(FQCN, loader, externalContext, false, source); + } catch (final Exception ex) { + LOGGER.error("There was a problem obtaining a LoggerContext using the configuration source [{}]", source, ex); + } + return null; + } + + /** + * Initializes the Logging Context. + * @param name The Context name. + * @param loader The ClassLoader for the Context (or null). + * @param configLocation The configuration for the logging context. + * @return The LoggerContext or null if an error occurred (check the status logger). + */ + public static LoggerContext initialize(final String name, final ClassLoader loader, final String configLocation) { + return initialize(name, loader, configLocation, null); + + } + + /** + * Initializes the Logging Context. + * @param name The Context name. + * @param loader The ClassLoader for the Context (or null). + * @param configLocation The configuration for the logging context (or null, or blank). + * @param externalContext The external context to be attached to the LoggerContext + * @return The LoggerContext or null if an error occurred (check the status logger). + */ + public static LoggerContext initialize(final String name, final ClassLoader loader, final String configLocation, + final Object externalContext) { + if (Strings.isBlank(configLocation)) { + return initialize(name, loader, (URI) null, externalContext); + } + if (configLocation.contains(",")) { + String[] parts = configLocation.split(","); + String scheme = null; + List<URI> uris = new ArrayList<>(parts.length); + for (String part : parts) { + URI uri = NetUtils.toURI(scheme != null ? scheme + ":" + part.trim() : part.trim()); + if (scheme == null && uri.getScheme() != null) { + scheme = uri.getScheme(); + } + uris.add(uri); + } + return initialize(name, loader, uris, externalContext); + } else { + return initialize(name, loader, NetUtils.toURI(configLocation), externalContext); + } + } + + /** + * Initializes the Logging Context. + * @param name The Context name. + * @param loader The ClassLoader for the Context (or null). + * @param configLocation The configuration for the logging context. + * @return The LoggerContext. + */ + public static LoggerContext initialize(final String name, final ClassLoader loader, final URI configLocation) { + return initialize(name, loader, configLocation, null); + } + + /** + * Initializes the Logging Context. + * @param name The Context name. + * @param loader The ClassLoader for the Context (or null). + * @param configLocation The configuration for the logging context (or null). + * @param externalContext The external context to be attached to the LoggerContext + * @return The LoggerContext. + */ + public static LoggerContext initialize(final String name, final ClassLoader loader, final URI configLocation, + final Object externalContext) { + + try { + final Log4jContextFactory factory = getFactory(); + return factory == null ? null : + factory.getContext(FQCN, loader, externalContext, false, configLocation, name); + } catch (final Exception ex) { + LOGGER.error("There was a problem initializing the LoggerContext [{}] using configuration at [{}].", + name, configLocation, ex); + } + return null; + } + + public static LoggerContext initialize(final String name, final ClassLoader loader, final List<URI> configLocations, + final Object externalContext) { + try { + final Log4jContextFactory factory = getFactory(); + return factory == null ? + null : + factory.getContext(FQCN, loader, externalContext, false, configLocations, name); + } catch (final Exception ex) { + LOGGER.error("There was a problem initializing the LoggerContext [{}] using configurations at [{}].", name, + configLocations, ex); + } + return null; + } + + /** + * Initializes the Logging Context. + * @param name The Context name. + * @param configLocation The configuration for the logging context. + * @return The LoggerContext or null if an error occurred (check the status logger). + */ + public static LoggerContext initialize(final String name, final String configLocation) { + return initialize(name, null, configLocation); + } + + /** + * Initializes the Logging Context. + * @param configuration The Configuration. + * @return The LoggerContext. + */ + public static LoggerContext initialize(final Configuration configuration) { + return initialize(null, configuration, null); + } + + /** + * Initializes the Logging Context. + * @param loader The ClassLoader. + * @param configuration The Configuration. + * @return The LoggerContext. + */ + public static LoggerContext initialize(final ClassLoader loader, final Configuration configuration) { + return initialize(loader, configuration, null); + } + + /** + * Initializes the Logging Context. + * @param loader The ClassLoader. + * @param configuration The Configuration. + * @param externalContext - The external context to be attached to the LoggerContext. + * @return The LoggerContext. + */ + public static LoggerContext initialize(final ClassLoader loader, final Configuration configuration, final Object externalContext) { + try { + final Log4jContextFactory factory = getFactory(); + return factory == null ? null : + factory.getContext(FQCN, loader, externalContext, false, configuration); + } catch (final Exception ex) { + LOGGER.error("There was a problem initializing the LoggerContext using configuration {}", + configuration.getName(), ex); + } + return null; + } + + /** + * Sets the levels of <code>parentLogger</code> and all 'child' loggers to the given <code>level</code>. + * @param parentLogger the parent logger + * @param level the new level + */ + public static void setAllLevels(final String parentLogger, final Level level) { + // 1) get logger config + // 2) if exact match, use it, if not, create it. + // 3) set level on logger config + // 4) update child logger configs with level + // 5) update loggers + final LoggerContext loggerContext = LoggerContext.getContext(false); + final Configuration config = loggerContext.getConfiguration(); + boolean set = setLevel(parentLogger, level, config); + for (final Map.Entry<String, LoggerConfig> entry : config.getLoggers().entrySet()) { + if (entry.getKey().startsWith(parentLogger)) { + set |= setLevel(entry.getValue(), level); + } + } + if (set) { + loggerContext.updateLoggers(); + } + } + + private static boolean setLevel(final LoggerConfig loggerConfig, final Level level) { + final boolean set = !loggerConfig.getLevel().equals(level); + if (set) { + loggerConfig.setLevel(level); + } + return set; + } + + /** + * Sets logger levels. + * + * @param levelMap + * a levelMap where keys are level names and values are new + * Levels. + */ + public static void setLevel(final Map<String, Level> levelMap) { + final LoggerContext loggerContext = LoggerContext.getContext(false); + final Configuration config = loggerContext.getConfiguration(); + boolean set = false; + for (final Map.Entry<String, Level> entry : levelMap.entrySet()) { + final String loggerName = entry.getKey(); + final Level level = entry.getValue(); + set |= setLevel(loggerName, level, config); + } + if (set) { + loggerContext.updateLoggers(); + } + } + + /** + * Sets a logger's level. + * + * @param loggerName + * the logger name + * @param level + * the new level + */ + public static void setLevel(final String loggerName, final Level level) { + final LoggerContext loggerContext = LoggerContext.getContext(false); + if (Strings.isEmpty(loggerName)) { + setRootLevel(level); + } else { + if (setLevel(loggerName, level, loggerContext.getConfiguration())) { + loggerContext.updateLoggers(); + } + } + } + + private static boolean setLevel(final String loggerName, final Level level, final Configuration config) { + boolean set; + LoggerConfig loggerConfig = config.getLoggerConfig(loggerName); + if (!loggerName.equals(loggerConfig.getName())) { + // TODO Should additivity be inherited? + loggerConfig = new LoggerConfig(loggerName, level, true); + config.addLogger(loggerName, loggerConfig); + loggerConfig.setLevel(level); + set = true; + } else { + set = setLevel(loggerConfig, level); + } + return set; + } + + /** + * Sets the root logger's level. + * + * @param level + * the new level + */ + public static void setRootLevel(final Level level) { + final LoggerContext loggerContext = LoggerContext.getContext(false); + final LoggerConfig loggerConfig = loggerContext.getConfiguration().getRootLogger(); + if (!loggerConfig.getLevel().equals(level)) { + loggerConfig.setLevel(level); + loggerContext.updateLoggers(); + } + } + + /** + * Shuts down the given logging context. + * @param ctx the logging context to shut down, may be null. + */ + public static void shutdown(final LoggerContext ctx) { + if (ctx != null) { + ctx.stop(); + } + } + + private Configurator() { + // empty + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultReliabilityStrategy.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultReliabilityStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultReliabilityStrategy.java index fd77429..18fcae4 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultReliabilityStrategy.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultReliabilityStrategy.java @@ -1,107 +1,107 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ - -package org.apache.logging.log4j.core.config; - -import java.util.Objects; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.message.Message; -import org.apache.logging.log4j.util.Supplier; - -/** - * Reliability strategy that assumes reconfigurations will never take place. - */ -public class DefaultReliabilityStrategy implements ReliabilityStrategy { - - private final LoggerConfig loggerConfig; - - public DefaultReliabilityStrategy(final LoggerConfig loggerConfig) { - 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) - */ - @Override - public void log(Supplier<LoggerConfig> reconfigured, String loggerName, String fqcn, Marker marker, Level level, - Message data, Throwable t) { - loggerConfig.log(loggerName, fqcn, marker, level, data, t); - } - - /* - * (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(Supplier<LoggerConfig> reconfigured, LogEvent event) { - loggerConfig.log(event); - } - - /* - * (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(Supplier<LoggerConfig> next) { - return this.loggerConfig; - } - - /* - * (non-Javadoc) - * - * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#afterLogEvent() - */ - @Override - public void afterLogEvent() { - // no action - } - - /* - * (non-Javadoc) - * - * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopAppenders() - */ - @Override - public void beforeStopAppenders() { - // no action - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopConfiguration(org.apache.logging.log4j.core - * .config.Configuration) - */ - @Override - public void beforeStopConfiguration(Configuration configuration) { - // no action - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ + +package org.apache.logging.log4j.core.config; + +import java.util.Objects; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.util.Supplier; + +/** + * Reliability strategy that assumes reconfigurations will never take place. + */ +public class DefaultReliabilityStrategy implements ReliabilityStrategy { + + private final LoggerConfig loggerConfig; + + public DefaultReliabilityStrategy(final LoggerConfig loggerConfig) { + 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) + */ + @Override + public void log(final Supplier<LoggerConfig> reconfigured, final String loggerName, final String fqcn, final Marker marker, final Level level, + final Message data, final Throwable t) { + loggerConfig.log(loggerName, fqcn, marker, level, data, t); + } + + /* + * (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) { + loggerConfig.log(event); + } + + /* + * (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) { + return this.loggerConfig; + } + + /* + * (non-Javadoc) + * + * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#afterLogEvent() + */ + @Override + public void afterLogEvent() { + // no action + } + + /* + * (non-Javadoc) + * + * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopAppenders() + */ + @Override + public void beforeStopAppenders() { + // no action + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopConfiguration(org.apache.logging.log4j.core + * .config.Configuration) + */ + @Override + public void beforeStopConfiguration(final Configuration configuration) { + // no action + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/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 f5fbfcc..c930f8b 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 @@ -1,135 +1,135 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ - -package org.apache.logging.log4j.core.config; - -import java.util.Objects; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.message.Message; -import org.apache.logging.log4j.util.Supplier; - -/** - * ReliabilityStrategy that uses read/write locks to prevent the LoggerConfig from stopping while it is in use. - */ -public class LockingReliabilityStrategy implements ReliabilityStrategy { - private final LoggerConfig loggerConfig; - private final ReadWriteLock reconfigureLock = new ReentrantReadWriteLock(); - private volatile boolean isStopping = false; - - public LockingReliabilityStrategy(final LoggerConfig loggerConfig) { - 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) - */ - @Override - public void log(final Supplier<LoggerConfig> reconfigured, final String loggerName, final String fqcn, - final Marker marker, final Level level, final Message data, final Throwable t) { - - final LoggerConfig config = getActiveLoggerConfig(reconfigured); - try { - config.log(loggerName, fqcn, marker, level, data, t); - } finally { - config.getReliabilityStrategy().afterLogEvent(); - } - } - - /* - * (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) { - final LoggerConfig config = getActiveLoggerConfig(reconfigured); - try { - config.log(event); - } finally { - config.getReliabilityStrategy().afterLogEvent(); - } - } - - /* - * (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) { - LoggerConfig result = this.loggerConfig; - if (!beforeLogEvent()) { - result = next.get(); - return result.getReliabilityStrategy().getActiveLoggerConfig(next); - } - return result; - } - - private boolean beforeLogEvent() { - reconfigureLock.readLock().lock(); - if (isStopping) { - reconfigureLock.readLock().unlock(); - return false; - } - return true; - } - - @Override - public void afterLogEvent() { - reconfigureLock.readLock().unlock(); - } - - /* - * (non-Javadoc) - * - * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopAppenders() - */ - @Override - public void beforeStopAppenders() { - reconfigureLock.writeLock().lock(); - try { - isStopping = true; - } finally { - reconfigureLock.writeLock().unlock(); - } - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopConfiguration(org.apache.logging.log4j.core - * .config.Configuration) - */ - @Override - public void beforeStopConfiguration(Configuration configuration) { - // no action - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ + +package org.apache.logging.log4j.core.config; + +import java.util.Objects; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.util.Supplier; + +/** + * ReliabilityStrategy that uses read/write locks to prevent the LoggerConfig from stopping while it is in use. + */ +public class LockingReliabilityStrategy implements ReliabilityStrategy { + private final LoggerConfig loggerConfig; + private final ReadWriteLock reconfigureLock = new ReentrantReadWriteLock(); + private volatile boolean isStopping = false; + + public LockingReliabilityStrategy(final LoggerConfig loggerConfig) { + 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) + */ + @Override + public void log(final Supplier<LoggerConfig> reconfigured, final String loggerName, final String fqcn, + final Marker marker, final Level level, final Message data, final Throwable t) { + + final LoggerConfig config = getActiveLoggerConfig(reconfigured); + try { + config.log(loggerName, fqcn, marker, level, data, t); + } finally { + config.getReliabilityStrategy().afterLogEvent(); + } + } + + /* + * (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) { + final LoggerConfig config = getActiveLoggerConfig(reconfigured); + try { + config.log(event); + } finally { + config.getReliabilityStrategy().afterLogEvent(); + } + } + + /* + * (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) { + LoggerConfig result = this.loggerConfig; + if (!beforeLogEvent()) { + result = next.get(); + return result.getReliabilityStrategy().getActiveLoggerConfig(next); + } + return result; + } + + private boolean beforeLogEvent() { + reconfigureLock.readLock().lock(); + if (isStopping) { + reconfigureLock.readLock().unlock(); + return false; + } + return true; + } + + @Override + public void afterLogEvent() { + reconfigureLock.readLock().unlock(); + } + + /* + * (non-Javadoc) + * + * @see org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopAppenders() + */ + @Override + public void beforeStopAppenders() { + reconfigureLock.writeLock().lock(); + try { + isStopping = true; + } finally { + reconfigureLock.writeLock().unlock(); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.logging.log4j.core.config.ReliabilityStrategy#beforeStopConfiguration(org.apache.logging.log4j.core + * .config.Configuration) + */ + @Override + public void beforeStopConfiguration(final Configuration configuration) { + // no action + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java index 8043ff5..e26407a 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java @@ -145,7 +145,7 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement } @Override - public T build(boolean initialize) { + public T build(final boolean initialize) { T configuration; try { if (source == null) { @@ -215,7 +215,7 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement } @Override - public LoggerComponentBuilder newAsyncLogger(final String name, final Level level, boolean includeLocation) { + public LoggerComponentBuilder newAsyncLogger(final String name, final Level level, final boolean includeLocation) { return new DefaultLoggerComponentBuilder(this, name, level.toString(), "AsyncLogger", includeLocation); } @@ -225,7 +225,7 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement } @Override - public LoggerComponentBuilder newAsyncLogger(final String name, final String level, boolean includeLocation) { + public LoggerComponentBuilder newAsyncLogger(final String name, final String level, final boolean includeLocation) { return new DefaultLoggerComponentBuilder(this, name, level, "AsyncLogger"); } @@ -235,7 +235,7 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement } @Override - public RootLoggerComponentBuilder newAsyncRootLogger(final Level level, boolean includeLocation) { + public RootLoggerComponentBuilder newAsyncRootLogger(final Level level, final boolean includeLocation) { return new DefaultRootLoggerComponentBuilder(this, level.toString(), "AsyncRoot", includeLocation); } @@ -245,7 +245,7 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement } @Override - public RootLoggerComponentBuilder newAsyncRootLogger(final String level, boolean includeLocation) { + public RootLoggerComponentBuilder newAsyncRootLogger(final String level, final boolean includeLocation) { return new DefaultRootLoggerComponentBuilder(this, level, "AsyncRoot", includeLocation); } @@ -295,7 +295,7 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement } @Override - public LoggerComponentBuilder newLogger(final String name, final Level level, boolean includeLocation) { + public LoggerComponentBuilder newLogger(final String name, final Level level, final boolean includeLocation) { return new DefaultLoggerComponentBuilder(this, name, level.toString(), includeLocation); } @@ -305,7 +305,7 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement } @Override - public LoggerComponentBuilder newLogger(final String name, final String level, boolean includeLocation) { + public LoggerComponentBuilder newLogger(final String name, final String level, final boolean includeLocation) { return new DefaultLoggerComponentBuilder(this, name, level, includeLocation); } @@ -315,7 +315,7 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement } @Override - public RootLoggerComponentBuilder newRootLogger(final Level level, boolean includeLocation) { + public RootLoggerComponentBuilder newRootLogger(final Level level, final boolean includeLocation) { return new DefaultRootLoggerComponentBuilder(this, level.toString(), includeLocation); } @@ -325,7 +325,7 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement } @Override - public RootLoggerComponentBuilder newRootLogger(final String level, boolean includeLocation) { + public RootLoggerComponentBuilder newRootLogger(final String level, final boolean includeLocation) { return new DefaultRootLoggerComponentBuilder(this, level, includeLocation); } @@ -390,7 +390,7 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement } @Override - public ConfigurationBuilder<T> addRootProperty(String key, String value) { + public ConfigurationBuilder<T> addRootProperty(final String key, final String value) { root.getAttributes().put(key, value); return this; } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultLoggerComponentBuilder.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultLoggerComponentBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultLoggerComponentBuilder.java index 37aba83..891e795 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultLoggerComponentBuilder.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultLoggerComponentBuilder.java @@ -47,7 +47,7 @@ class DefaultLoggerComponentBuilder extends DefaultComponentAndConfigurationBuil * @param includeLocation */ public DefaultLoggerComponentBuilder(final DefaultConfigurationBuilder<? extends Configuration> builder, final String name, - final String level, boolean includeLocation) { + final String level, final boolean includeLocation) { super(builder, name, "Logger"); addAttribute("level", level); addAttribute("includeLocation", includeLocation); @@ -75,7 +75,7 @@ class DefaultLoggerComponentBuilder extends DefaultComponentAndConfigurationBuil * @param includeLocation */ public DefaultLoggerComponentBuilder(final DefaultConfigurationBuilder<? extends Configuration> builder, final String name, - final String level, final String type, boolean includeLocation) { + final String level, final String type, final boolean includeLocation) { super(builder, name, type); addAttribute("level", level); addAttribute("includeLocation", includeLocation);
