Skip to content

Commit 72205bf

Browse files
Feature/2.x/mongodb next gg (#2486)
* Add module log4j-mongodb to track the current MongoDB driver (currently version 5) - Work around `PluginProcessor` restrictions. - The `PluginProcessor` assumes that the factory method of a `@Plugin`-annotated class returns an instance of the class itself. - We workaround the problem adding an `implements NoSqlProvider` clause to the `MongoDbProvider` class. * Deprecate the log4j-mongodb4 module in favor of log4j-mongodb * Remove module log4j-mongodb3, use log4j-mongodb instead Note: log4j-mongodb4 is deprecated for removal * Deprecate the log4j-mongodb4 module in favor of log4j-mongodb * Bump MongoDB version to test from 4.4 to 7.0.8 Co-authored-by: Piotr P. Karwasz <[email protected]> * Update package-info.java * Fix compilation * Bump tests from MongoDB Server 4.4 to 7.0 * Use AB order in modules --------- Co-authored-by: Piotr P. Karwasz <[email protected]>
1 parent a19eea5 commit 72205bf

34 files changed

+308
-818
lines changed

log4j-mongodb3/pom.xml log4j-mongodb/pom.xml

+13-33
Original file line numberDiff line numberDiff line change
@@ -16,69 +16,57 @@
1616
~ limitations under the License.
1717
-->
1818
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
19-
2019
<modelVersion>4.0.0</modelVersion>
21-
2220
<parent>
2321
<groupId>org.apache.logging.log4j</groupId>
2422
<artifactId>log4j</artifactId>
2523
<version>${revision}</version>
2624
<relativePath>../log4j-parent</relativePath>
2725
</parent>
28-
29-
<artifactId>log4j-mongodb3</artifactId>
30-
31-
<name>Apache Log4j MongoDB 3</name>
32-
<description>MongoDB appender for Log4j using the MongoDB 3 driver API.</description>
33-
26+
<artifactId>log4j-mongodb</artifactId>
27+
<name>Apache Log4j MongoDB Appender</name>
28+
<description>MongoDB appender for Log4j using the MongoDB 5 driver API.</description>
3429
<properties>
35-
36-
<!--
37-
~ OSGi and JPMS options
38-
-->
39-
<bnd-extra-module-options>
40-
<!-- Filebased module names: MUST be static -->
41-
mongodb.driver.legacy;substitute="mongodb-driver-legacy";static=true;transitive=false
42-
</bnd-extra-module-options>
30+
<!-- OSGi and JPMS options -->
4331
<Fragment-Host>org.apache.logging.log4j.core</Fragment-Host>
44-
4532
<!-- Dependency versions -->
46-
<mongodb3.version>3.12.14</mongodb3.version>
33+
<mongodb5.version>5.0.1</mongodb5.version>
34+
<!-- TODO: Remove in next release after 2.24.0. -->
35+
<bnd.baseline.fail.on.missing>false</bnd.baseline.fail.on.missing>
36+
<bnd.baseline.skip>true</bnd.baseline.skip>
4737
</properties>
48-
4938
<dependencyManagement>
5039
<dependencies>
5140
<dependency>
5241
<groupId>org.mongodb</groupId>
5342
<artifactId>bson</artifactId>
54-
<version>${mongodb3.version}</version>
43+
<version>${mongodb5.version}</version>
5544
</dependency>
5645
<dependency>
5746
<groupId>org.mongodb</groupId>
5847
<artifactId>mongodb-driver-core</artifactId>
59-
<version>${mongodb3.version}</version>
48+
<version>${mongodb5.version}</version>
6049
</dependency>
6150
<dependency>
6251
<groupId>org.mongodb</groupId>
6352
<artifactId>mongodb-driver-legacy</artifactId>
64-
<version>${mongodb3.version}</version>
53+
<version>${mongodb5.version}</version>
6554
</dependency>
6655
<dependency>
6756
<groupId>org.mongodb</groupId>
6857
<artifactId>mongodb-driver-sync</artifactId>
69-
<version>${mongodb3.version}</version>
58+
<version>${mongodb5.version}</version>
7059
</dependency>
7160
</dependencies>
7261
</dependencyManagement>
73-
7462
<dependencies>
7563
<dependency>
7664
<groupId>org.apache.logging.log4j</groupId>
7765
<artifactId>log4j-api</artifactId>
7866
</dependency>
7967
<dependency>
8068
<groupId>org.apache.logging.log4j</groupId>
81-
<artifactId>log4j-core</artifactId>
69+
<artifactId>log4j-mongodb4</artifactId>
8270
</dependency>
8371
<dependency>
8472
<groupId>org.mongodb</groupId>
@@ -88,10 +76,6 @@
8876
<groupId>org.mongodb</groupId>
8977
<artifactId>mongodb-driver-core</artifactId>
9078
</dependency>
91-
<dependency>
92-
<groupId>org.mongodb</groupId>
93-
<artifactId>mongodb-driver-legacy</artifactId>
94-
</dependency>
9579
<dependency>
9680
<groupId>org.mongodb</groupId>
9781
<artifactId>mongodb-driver-sync</artifactId>
@@ -144,10 +128,8 @@
144128
<scope>test</scope>
145129
</dependency>
146130
</dependencies>
147-
148131
<build>
149132
<plugins>
150-
151133
<plugin>
152134
<groupId>org.apache.maven.plugins</groupId>
153135
<artifactId>maven-surefire-plugin</artifactId>
@@ -163,8 +145,6 @@
163145
</dependency>
164146
</dependencies>
165147
</plugin>
166-
167148
</plugins>
168149
</build>
169-
170150
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.logging.log4j.mongodb;
18+
19+
import org.apache.logging.log4j.core.Core;
20+
import org.apache.logging.log4j.core.appender.nosql.NoSqlProvider;
21+
import org.apache.logging.log4j.core.config.plugins.Plugin;
22+
import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
23+
import org.apache.logging.log4j.mongodb4.MongoDb4Connection;
24+
import org.apache.logging.log4j.mongodb4.MongoDb4Provider;
25+
import org.apache.logging.log4j.mongodb4.MongoDb4Provider.Builder;
26+
27+
/**
28+
* Delegates to {@link MongoDb4Provider} under the name {@code MongoDb}.
29+
*/
30+
/*
31+
* TODO: Currently the
32+
* {@link org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor}
33+
* assumes that the class generated by the plugin is the same as the annotated class.
34+
* To work around this we declare this class abstract and let it implement
35+
* {@link NoSqlProvider}.
36+
*/
37+
@Plugin(name = "MongoDb", category = Core.CATEGORY_NAME, printObject = true)
38+
public abstract class MongoDbProvider implements NoSqlProvider<MongoDb4Connection> {
39+
40+
private MongoDbProvider() {}
41+
42+
@PluginBuilderFactory
43+
public static <B extends Builder<B>> B newBuilder() {
44+
return MongoDb4Provider.newBuilder();
45+
}
46+
}

log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/package-info.java log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/package-info.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
* limitations under the license.
1616
*/
1717
/**
18-
* The classes in this package contain the MongoDB provider for the NoSQL Appender.
18+
* The classes in this package contain the MongoDB provider for the NoSQL
19+
* Appender.
1920
*/
2021
@Export
2122
@Open("org.apache.logging.log4j.core")
22-
@Version("2.20.1")
23-
package org.apache.logging.log4j.mongodb3;
23+
@Version("2.24.0")
24+
package org.apache.logging.log4j.mongodb;
2425

2526
import aQute.bnd.annotation.jpms.Open;
2627
import org.osgi.annotation.bundle.Export;

log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3CappedTest.java log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/AbstractMongoDbCappedTest.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,26 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.apache.logging.log4j.mongodb3;
17+
package org.apache.logging.log4j.mongodb;
1818

19-
import com.mongodb.MongoClient;
19+
import com.mongodb.client.MongoClient;
2020
import com.mongodb.client.MongoCollection;
2121
import com.mongodb.client.MongoDatabase;
2222
import org.apache.logging.log4j.Logger;
2323
import org.apache.logging.log4j.core.LoggerContext;
24-
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
2524
import org.bson.Document;
2625
import org.junit.jupiter.api.Assertions;
2726
import org.junit.jupiter.api.Test;
2827

29-
@UsingMongoDb3
30-
@LoggerContextSource("log4j2-mongodb-capped.xml")
31-
public class MongoDb3CappedTest {
28+
public abstract class AbstractMongoDbCappedTest {
3229

3330
@Test
3431
public void test(final LoggerContext ctx, final MongoClient mongoClient) {
35-
final Logger logger = ctx.getLogger(MongoDb3CappedTest.class);
32+
final Logger logger = ctx.getLogger(AbstractMongoDbCappedTest.class);
3633
logger.info("Hello log");
37-
final MongoDatabase database = mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME);
34+
final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
3835
Assertions.assertNotNull(database);
39-
final MongoCollection<Document> collection = database.getCollection(MongoDb3TestConstants.COLLECTION_NAME);
36+
final MongoCollection<Document> collection = database.getCollection(MongoDbTestConstants.COLLECTION_NAME);
4037
Assertions.assertNotNull(collection);
4138
final Document first = collection.find().first();
4239
Assertions.assertNotNull(first);

log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AdditionalFieldsTest.java log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAdditionalFieldsTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.apache.logging.log4j.mongodb3;
17+
package org.apache.logging.log4j.mongodb;
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertNotNull;
2121

22-
import com.mongodb.MongoClient;
2322
import com.mongodb.client.FindIterable;
23+
import com.mongodb.client.MongoClient;
2424
import com.mongodb.client.MongoCollection;
2525
import com.mongodb.client.MongoDatabase;
2626
import org.apache.logging.log4j.Logger;
@@ -29,18 +29,18 @@
2929
import org.bson.Document;
3030
import org.junit.jupiter.api.Test;
3131

32-
@UsingMongoDb3
32+
@UsingMongoDb
3333
@LoggerContextSource("log4j2-mongodb-additional-fields.xml")
34-
public class MongoDb3AdditionalFieldsTest {
34+
public class MongoDbAdditionalFieldsTest {
3535

3636
@Test
3737
public void test(final LoggerContext ctx, final MongoClient mongoClient) {
38-
final Logger logger = ctx.getLogger(MongoDb3AdditionalFieldsTest.class);
38+
final Logger logger = ctx.getLogger(MongoDbAdditionalFieldsTest.class);
3939
logger.info("Hello log 1");
4040
logger.info("Hello log 2", new RuntimeException("Hello ex 2"));
41-
final MongoDatabase database = mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME);
41+
final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
4242
assertNotNull(database);
43-
final MongoCollection<Document> collection = database.getCollection(MongoDb3TestConstants.COLLECTION_NAME);
43+
final MongoCollection<Document> collection = database.getCollection(MongoDbTestConstants.COLLECTION_NAME);
4444
assertNotNull(collection);
4545
final FindIterable<Document> found = collection.find();
4646
final Document first = found.first();

log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AuthFailureTest.java log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.apache.logging.log4j.mongodb3;
17+
package org.apache.logging.log4j.mongodb;
1818

1919
import static org.junit.jupiter.api.Assertions.assertNotNull;
2020
import static org.junit.jupiter.api.Assertions.assertNull;
2121

22-
import com.mongodb.MongoClient;
22+
import com.mongodb.client.MongoClient;
2323
import com.mongodb.client.MongoCollection;
2424
import com.mongodb.client.MongoDatabase;
2525
import org.apache.logging.log4j.Logger;
@@ -28,17 +28,17 @@
2828
import org.bson.Document;
2929
import org.junit.jupiter.api.Test;
3030

31-
@UsingMongoDb3
31+
@UsingMongoDb
3232
@LoggerContextSource("log4j2-mongodb-auth-failure.xml")
33-
public class MongoDb3AuthFailureTest {
33+
public class MongoDbAuthFailureTest {
3434

3535
@Test
3636
public void test(final LoggerContext ctx, final MongoClient mongoClient) {
37-
final Logger logger = ctx.getLogger(MongoDb3AuthFailureTest.class);
37+
final Logger logger = ctx.getLogger(MongoDbAuthFailureTest.class);
3838
logger.info("Hello log");
39-
final MongoDatabase database = mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME);
39+
final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
4040
assertNotNull(database);
41-
final MongoCollection<Document> collection = database.getCollection(MongoDb3TestConstants.DATABASE_NAME);
41+
final MongoCollection<Document> collection = database.getCollection(MongoDbTestConstants.DATABASE_NAME);
4242
assertNotNull(collection);
4343
final Document first = collection.find().first();
4444
assertNull(first);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.logging.log4j.mongodb;
18+
19+
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
20+
21+
@UsingMongoDb
22+
@LoggerContextSource("log4j2-mongodb-capped-int.xml")
23+
public class MongoDbCappedIntTest extends AbstractMongoDbCappedTest {
24+
25+
// test is in superclass
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.logging.log4j.mongodb;
18+
19+
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
20+
21+
@UsingMongoDb
22+
@LoggerContextSource("log4j2-mongodb-capped-long.xml")
23+
public class MongoDbCappedLongTest extends AbstractMongoDbCappedTest {
24+
25+
// test is in superclass
26+
}

log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3MapMessageTest.java log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.apache.logging.log4j.mongodb3;
17+
package org.apache.logging.log4j.mongodb;
1818

19-
import com.mongodb.MongoClient;
19+
import com.mongodb.client.MongoClient;
2020
import com.mongodb.client.MongoCollection;
2121
import com.mongodb.client.MongoDatabase;
2222
import org.apache.logging.log4j.Logger;
@@ -27,20 +27,20 @@
2727
import org.junit.jupiter.api.Assertions;
2828
import org.junit.jupiter.api.Test;
2929

30-
@UsingMongoDb3
30+
@UsingMongoDb
3131
@LoggerContextSource("log4j2-mongodb-map-message.xml")
32-
public class MongoDb3MapMessageTest {
32+
public class MongoDbMapMessageTest {
3333

3434
@Test
3535
public void test(final LoggerContext ctx, final MongoClient mongoClient) {
36-
final Logger logger = ctx.getLogger(MongoDb3MapMessageTest.class);
36+
final Logger logger = ctx.getLogger(MongoDbMapMessageTest.class);
3737
final MapMessage<?, Object> mapMessage = new MapMessage<>();
3838
mapMessage.with("SomeName", "SomeValue");
3939
mapMessage.with("SomeInt", 1);
4040
logger.info(mapMessage);
41-
final MongoDatabase database = mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME);
41+
final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
4242
Assertions.assertNotNull(database);
43-
final MongoCollection<Document> collection = database.getCollection(MongoDb3TestConstants.COLLECTION_NAME);
43+
final MongoCollection<Document> collection = database.getCollection(MongoDbTestConstants.COLLECTION_NAME);
4444
Assertions.assertNotNull(collection);
4545
final Document first = collection.find().first();
4646
Assertions.assertNotNull(first);

0 commit comments

Comments
 (0)