Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.config.Configuration;
Expand Down Expand Up @@ -67,21 +68,34 @@ public void resetLevel(final LoggerContext context) {
@Timeout(3)
public void testUpdateLoggersPropertyListeners(final LoggerContext context) throws Exception {
final Configuration config = context.getConfiguration();
context.addConfigurationStartedListener(configuration -> assertSame(config, configuration));
context.updateLoggers();
final Consumer<Configuration> listener = configuration -> assertSame(config, configuration);
context.addConfigurationStartedListener(listener);
try {
context.updateLoggers();
} finally {
context.removeConfigurationStartedListener(listener);
}
}

@Test
@SuppressWarnings("deprecation")
void propertyChangeListenerReceivesOldAndNewConfigurationOnReconfiguration(final LoggerContext context) {
// Given a java.beans listener, as registered by Log4j Core 2 consumers such as Micrometer
final List<PropertyChangeEvent> events = new ArrayList<>();
context.addPropertyChangeListener(events::add);
final PropertyChangeListener listener = events::add;
context.addPropertyChangeListener(listener);
final Configuration previous = context.getConfiguration();
final Configuration replacement = new DefaultConfiguration();

// When the configuration is replaced
context.setConfiguration(replacement);
try {
context.setConfiguration(replacement);
} finally {
// Restore the shared context for the other tests in this class; `previous` has been stopped,
// so reload the original configuration file instead of reinstating it.
context.removePropertyChangeListener(listener);
context.reconfigure();
}

// Then the listener sees the old and the new configuration
assertThat(events).isNotEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,19 @@ public B asBuilder() {
}
}

/**
* Constructor that sets the name, level and additive values.
* @deprecated - For comapatibilty with 2.x.
Comment thread
rgoers marked this conversation as resolved.
Resolved
*
* @param name The Logger name.
* @param level The Level.
* @param additive true if the Logger is additive, false otherwise.
*/
@Deprecated
public LoggerConfig(final String name, final Level level, final boolean additive) {
Comment thread
rgoers marked this conversation as resolved.
Resolved
this(name, Collections.emptyList(), null, level, additive, null, null, true);
}

/**
* Constructor that sets the name, level and additive values.
*
Expand Down