Search in sources :

Example 1 with FailoverAppender

use of org.apache.logging.log4j.core.appender.FailoverAppender in project logging-log4j2 by apache.

the class ValidatingPluginWithFailoverTest method setUp.

@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() throws Exception {
    final PluginManager manager = new PluginManager(Core.CATEGORY_NAME);
    manager.collectPlugins();
    plugin = (PluginType<FailoverAppender>) manager.getPluginType("failover");
    assertNotNull(plugin, "Rebuild this module to make sure annotation processing kicks in.");
    AppenderRef appenderRef = AppenderRef.createAppenderRef("List", Level.ALL, null);
    node = new Node(null, "failover", plugin);
    Node failoversNode = new Node(node, "Failovers", manager.getPluginType("Failovers"));
    Node appenderRefNode = new Node(failoversNode, "appenderRef", manager.getPluginType("appenderRef"));
    appenderRefNode.getAttributes().put("ref", "file");
    appenderRefNode.setObject(appenderRef);
    failoversNode.getChildren().add(appenderRefNode);
    failoversNode.setObject(FailoversPlugin.createFailovers(appenderRef));
    node.getAttributes().put("primary", "CONSOLE");
    node.getAttributes().put("name", "Failover");
    node.getChildren().add(failoversNode);
}
Also used : PluginManager(org.apache.logging.log4j.plugins.util.PluginManager) Node(org.apache.logging.log4j.plugins.Node) FailoverAppender(org.apache.logging.log4j.core.appender.FailoverAppender) AppenderRef(org.apache.logging.log4j.core.config.AppenderRef) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with FailoverAppender

use of org.apache.logging.log4j.core.appender.FailoverAppender in project logging-log4j2 by apache.

the class ValidatingPluginWithFailoverTest method testDoesNotLog_NoParameterThatMatchesElement_message.

@Test
public void testDoesNotLog_NoParameterThatMatchesElement_message() {
    final StatusListener listener = mock(StatusListener.class);
    when(listener.getStatusLevel()).thenReturn(Level.WARN);
    // @formatter:off
    final PluginBuilder builder = new PluginBuilder(plugin).setConfiguration(new NullConfiguration()).setConfigurationNode(node);
    // @formatter:on
    StatusLogger.getLogger().registerListener(listener);
    final FailoverAppender failoverAppender = (FailoverAppender) builder.build();
    verify(listener, times(1)).getStatusLevel();
    verify(listener, never()).log(any(StatusData.class));
    verifyNoMoreInteractions(listener);
    assertNotNull(failoverAppender);
    assertEquals("Failover", failoverAppender.getName());
}
Also used : FailoverAppender(org.apache.logging.log4j.core.appender.FailoverAppender) StatusListener(org.apache.logging.log4j.status.StatusListener) PluginBuilder(org.apache.logging.log4j.core.config.plugins.util.PluginBuilder) StatusData(org.apache.logging.log4j.status.StatusData) NullConfiguration(org.apache.logging.log4j.core.config.NullConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

FailoverAppender (org.apache.logging.log4j.core.appender.FailoverAppender)2 AppenderRef (org.apache.logging.log4j.core.config.AppenderRef)1 NullConfiguration (org.apache.logging.log4j.core.config.NullConfiguration)1 PluginBuilder (org.apache.logging.log4j.core.config.plugins.util.PluginBuilder)1 Node (org.apache.logging.log4j.plugins.Node)1 PluginManager (org.apache.logging.log4j.plugins.util.PluginManager)1 StatusData (org.apache.logging.log4j.status.StatusData)1 StatusListener (org.apache.logging.log4j.status.StatusListener)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1