Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion log4j-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@
<!--
~ OSGi and JPMS options
-->
<disruptor.support.range>[3.4,5)</disruptor.support.range>
<bnd-multi-release>true</bnd-multi-release>
<bnd-extra-package-options>
<!-- Annotations only -->
org.jspecify.*;resolution:=optional,
<!-- External optional dependencies -->
com.conversantmedia.util.concurrent;resolution:=optional;
com.fasterxml.jackson.*;resolution:=optional,
com.lmax.disruptor.*;resolution:=optional,
com.lmax.disruptor.*;version="${disruptor.support.range}";resolution:=optional,
javax.activation;resolution:=optional,
javax.jms;version="[1.1,3)";resolution:=optional,
javax.mail.*;version="[1.6,2)";resolution:=optional,
Expand Down
47 changes: 47 additions & 0 deletions log4j-osgi-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
<artifactId>log4j-to-slf4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down Expand Up @@ -233,9 +238,30 @@
</classpathDependencyExcludes>
<excludes>
<exclude>org.apache.logging.log4j.osgi.tests.FelixLoadApiBundleTest</exclude>
<exclude>org.apache.logging.log4j.osgi.tests.DisruptorTest</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>test-equinox-disruptor</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<classpathDependencyExcludes combine.children="append">
<!-- Ensure that Disruptor is not accidentally loaded from the parent classpath -->
<exclude>com.lmax.disruptor:disruptor</exclude>
<exclude>org.apache.felix:org.apache.felix.framework</exclude>
</classpathDependencyExcludes>
<includes>
<include>org.apache.logging.log4j.osgi.tests.DisruptorTest</include>
</includes>
<systemPropertyVariables>
<log4j2.contextSelector>org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector
</log4j2.contextSelector>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>test-felix</id>
<goals>
Expand All @@ -247,9 +273,30 @@
</classpathDependencyExcludes>
<excludes>
<exclude>org.apache.logging.log4j.osgi.tests.EquinoxLoadApiBundleTest</exclude>
<exclude>org.apache.logging.log4j.osgi.tests.DisruptorTest</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>test-felix-disruptor</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<classpathDependencyExcludes combine.children="append">
<!-- Ensure that Disruptor is not accidentally loaded from the parent classpath -->
<exclude>com.lmax.disruptor:disruptor</exclude>
<exclude>org.eclipse.platform:org.eclipse.osgi</exclude>
</classpathDependencyExcludes>
<includes>
<include>org.apache.logging.log4j.osgi.tests.DisruptorTest</include>
</includes>
<systemPropertyVariables>
<log4j2.contextSelector>org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector
</log4j2.contextSelector>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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.osgi.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.linkBundle;
import static org.ops4j.pax.exam.CoreOptions.options;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.async.AsyncLoggerContext;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;

@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class DisruptorTest {

@org.ops4j.pax.exam.Configuration
public Option[] config() {
return options(
linkBundle("org.apache.logging.log4j.api"),
linkBundle("org.apache.logging.log4j.core"),
linkBundle("com.lmax.disruptor"),
// required by Pax Exam's logging
linkBundle("org.objectweb.asm"),
linkBundle("org.objectweb.asm.commons"),
linkBundle("org.objectweb.asm.tree"),
linkBundle("org.objectweb.asm.tree.analysis"),
linkBundle("org.objectweb.asm.util"),
linkBundle("org.apache.aries.spifly.dynamic.bundle").startLevel(2),
linkBundle("slf4j.api"),
linkBundle("ch.qos.logback.classic"),
linkBundle("ch.qos.logback.core"),
junitBundles());
}

@Test
public void testDisruptorLog() {
// Logger context
LoggerContext context = getLoggerContext();
assertTrue("LoggerContext is an instance of AsyncLoggerContext", context instanceof AsyncLoggerContext);
final CustomConfiguration custom = (CustomConfiguration) context.getConfiguration();
// Logging
final Logger logger = LogManager.getLogger(getClass());
logger.info("Hello OSGI from Log4j2!");

context.stop();
assertEquals(1, custom.getEvents().size());
final LogEvent event = custom.getEvents().get(0);
assertEquals("Hello OSGI from Log4j2!", event.getMessage().getFormattedMessage());
assertEquals(Level.INFO, event.getLevel());
custom.clearEvents();
}

private static LoggerContext getLoggerContext() {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
assertEquals("AsyncDefault", ctx.getName());
return ctx;
}
}
8 changes: 8 additions & 0 deletions src/changelog/.2.x.x/3706_osgi-disruptor.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://logging.apache.org/xml/ns"
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="fixed">
<issue id="3706" link="https://github.com/apache/logging-log4j2/issues/3706"/>
<description format="asciidoc">Fixes OSGi descriptor to accept Disruptor 4.</description>
</entry>
2 changes: 1 addition & 1 deletion src/changelog/2.23.0/add_support_for_disruptor_4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
xmlns="https://logging.apache.org/xml/ns"
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="added">
<issue id="1821" link="https://github.com/apache/logging-log4j2/pull/1821"/>
<issue id="1829" link="https://github.com/apache/logging-log4j2/issues/1829"/>
<description format="asciidoc">Added support for LMAX Disruptor 4.x</description>
</entry>
Loading