This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/2.x by this push:
new 72205bf069 Feature/2.x/mongodb next gg (#2486)
72205bf069 is described below
commit 72205bf069dca257d03a81731b7dae282038ef33
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Apr 19 17:49:31 2024 -0400
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]>
---
.../.log4j-plugin-processing-activator | 0
{log4j-mongodb3 => log4j-mongodb}/pom.xml | 46 +--
.../logging/log4j/mongodb/MongoDbProvider.java | 46 +++
.../logging/log4j/mongodb}/package-info.java | 7 +-
.../log4j/mongodb/AbstractMongoDbCappedTest.java | 15 +-
.../log4j/mongodb/MongoDbAdditionalFieldsTest.java | 14 +-
.../log4j/mongodb/MongoDbAuthFailureTest.java | 14 +-
.../log4j/mongodb/MongoDbCappedIntTest.java | 12 +-
.../log4j/mongodb/MongoDbCappedLongTest.java | 12 +-
.../log4j/mongodb/MongoDbMapMessageTest.java | 14 +-
.../logging/log4j/mongodb/MongoDbResolver.java | 26 +-
.../logging/log4j/mongodb/MongoDbResolverTest.java | 8 +-
.../apache/logging/log4j/mongodb/MongoDbTest.java | 14 +-
.../log4j/mongodb/MongoDbTestConstants.java | 4 +-
.../apache/logging/log4j/mongodb/UsingMongoDb.java | 6 +-
.../resources/log4j2-mongodb-additional-fields.xml | 5 +-
.../test/resources/log4j2-mongodb-auth-failure.xml | 4 +-
.../test/resources/log4j2-mongodb-capped-int.xml | 6 +-
.../test/resources/log4j2-mongodb-capped-long.xml | 7 +-
.../test/resources/log4j2-mongodb-map-message.xml | 3 +-
.../src/test/resources/log4j2-mongodb.xml | 3 +-
.../apache/logging/log4j/mongodb3/LevelCodec.java | 52 ---
.../logging/log4j/mongodb3/MongoDbConnection.java | 102 ------
.../log4j/mongodb3/MongoDbDocumentObject.java | 61 ----
.../log4j/mongodb3/MongoDbDocumentObjectCodec.java | 49 ---
.../logging/log4j/mongodb3/MongoDbProvider.java | 352 ---------------------
.../logging/log4j/mongodb4/MongoDb4Provider.java | 5 +-
.../logging/log4j/mongodb4/MongoDb4Resolver.java | 2 +-
pom.xml | 6 +-
src/changelog/.2.x.x/add_log4j_mongodb.xml | 7 +
src/changelog/.2.x.x/deprecate_log4j_mongodb4.xml | 7 +
src/changelog/.2.x.x/remove_log4j_mongodb3.xml | 7 +
.../modules/ROOT/pages/manual/appenders.adoc | 154 ++++-----
.../antora/modules/ROOT/pages/manual/messages.adoc | 2 +-
34 files changed, 242 insertions(+), 830 deletions(-)
diff --git a/log4j-mongodb3/.log4j-plugin-processing-activator
b/log4j-mongodb/.log4j-plugin-processing-activator
similarity index 100%
rename from log4j-mongodb3/.log4j-plugin-processing-activator
rename to log4j-mongodb/.log4j-plugin-processing-activator
diff --git a/log4j-mongodb3/pom.xml b/log4j-mongodb/pom.xml
similarity index 85%
rename from log4j-mongodb3/pom.xml
rename to log4j-mongodb/pom.xml
index b1225582b2..dd3b68facc 100644
--- a/log4j-mongodb3/pom.xml
+++ b/log4j-mongodb/pom.xml
@@ -16,61 +16,49 @@
~ limitations under the License.
-->
<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">
-
<modelVersion>4.0.0</modelVersion>
-
<parent>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>
<version>${revision}</version>
<relativePath>../log4j-parent</relativePath>
</parent>
-
- <artifactId>log4j-mongodb3</artifactId>
-
- <name>Apache Log4j MongoDB 3</name>
- <description>MongoDB appender for Log4j using the MongoDB 3 driver
API.</description>
-
+ <artifactId>log4j-mongodb</artifactId>
+ <name>Apache Log4j MongoDB Appender</name>
+ <description>MongoDB appender for Log4j using the MongoDB 5 driver
API.</description>
<properties>
-
- <!--
- ~ OSGi and JPMS options
- -->
- <bnd-extra-module-options>
- <!-- Filebased module names: MUST be static -->
-
mongodb.driver.legacy;substitute="mongodb-driver-legacy";static=true;transitive=false
- </bnd-extra-module-options>
+ <!-- OSGi and JPMS options -->
<Fragment-Host>org.apache.logging.log4j.core</Fragment-Host>
-
<!-- Dependency versions -->
- <mongodb3.version>3.12.14</mongodb3.version>
+ <mongodb5.version>5.0.1</mongodb5.version>
+ <!-- TODO: Remove in next release after 2.24.0. -->
+ <bnd.baseline.fail.on.missing>false</bnd.baseline.fail.on.missing>
+ <bnd.baseline.skip>true</bnd.baseline.skip>
</properties>
-
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
- <version>${mongodb3.version}</version>
+ <version>${mongodb5.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
- <version>${mongodb3.version}</version>
+ <version>${mongodb5.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-legacy</artifactId>
- <version>${mongodb3.version}</version>
+ <version>${mongodb5.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
- <version>${mongodb3.version}</version>
+ <version>${mongodb5.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
-
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
@@ -78,7 +66,7 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
+ <artifactId>log4j-mongodb4</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
@@ -88,10 +76,6 @@
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
</dependency>
- <dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>mongodb-driver-legacy</artifactId>
- </dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
@@ -144,10 +128,8 @@
<scope>test</scope>
</dependency>
</dependencies>
-
<build>
<plugins>
-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@@ -163,8 +145,6 @@
</dependency>
</dependencies>
</plugin>
-
</plugins>
</build>
-
</project>
diff --git
a/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbProvider.java
b/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbProvider.java
new file mode 100644
index 0000000000..0828b16648
--- /dev/null
+++
b/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbProvider.java
@@ -0,0 +1,46 @@
+/*
+ * 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.mongodb;
+
+import org.apache.logging.log4j.core.Core;
+import org.apache.logging.log4j.core.appender.nosql.NoSqlProvider;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
+import org.apache.logging.log4j.mongodb4.MongoDb4Connection;
+import org.apache.logging.log4j.mongodb4.MongoDb4Provider;
+import org.apache.logging.log4j.mongodb4.MongoDb4Provider.Builder;
+
+/**
+ * Delegates to {@link MongoDb4Provider} under the name {@code MongoDb}.
+ */
+/*
+ * TODO: Currently the
+ * {@link
org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor}
+ * assumes that the class generated by the plugin is the same as the
annotated class.
+ * To work around this we declare this class abstract and let it implement
+ * {@link NoSqlProvider}.
+ */
+@Plugin(name = "MongoDb", category = Core.CATEGORY_NAME, printObject = true)
+public abstract class MongoDbProvider implements
NoSqlProvider<MongoDb4Connection> {
+
+ private MongoDbProvider() {}
+
+ @PluginBuilderFactory
+ public static <B extends Builder<B>> B newBuilder() {
+ return MongoDb4Provider.newBuilder();
+ }
+}
diff --git
a/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/package-info.java
b/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/package-info.java
similarity index 92%
rename from
log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/package-info.java
rename to
log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/package-info.java
index 9a8fe2c118..3ff159c9e5 100644
---
a/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/package-info.java
+++
b/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/package-info.java
@@ -15,12 +15,13 @@
* limitations under the license.
*/
/**
- * The classes in this package contain the MongoDB provider for the NoSQL
Appender.
+ * The classes in this package contain the MongoDB provider for the NoSQL
+ * Appender.
*/
@Export
@Open("org.apache.logging.log4j.core")
-@Version("2.20.1")
-package org.apache.logging.log4j.mongodb3;
+@Version("2.24.0")
+package org.apache.logging.log4j.mongodb;
import aQute.bnd.annotation.jpms.Open;
import org.osgi.annotation.bundle.Export;
diff --git
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3CappedTest.java
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/AbstractMongoDbCappedTest.java
similarity index 80%
rename from
log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3CappedTest.java
rename to
log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/AbstractMongoDbCappedTest.java
index 71ad196192..07e3933994 100644
---
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3CappedTest.java
+++
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/AbstractMongoDbCappedTest.java
@@ -14,29 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.mongodb3;
+package org.apache.logging.log4j.mongodb;
-import com.mongodb.MongoClient;
+import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.bson.Document;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-@UsingMongoDb3
-@LoggerContextSource("log4j2-mongodb-capped.xml")
-public class MongoDb3CappedTest {
+public abstract class AbstractMongoDbCappedTest {
@Test
public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger = ctx.getLogger(MongoDb3CappedTest.class);
+ final Logger logger = ctx.getLogger(AbstractMongoDbCappedTest.class);
logger.info("Hello log");
- final MongoDatabase database =
mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME);
+ final MongoDatabase database =
mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
Assertions.assertNotNull(database);
- final MongoCollection<Document> collection =
database.getCollection(MongoDb3TestConstants.COLLECTION_NAME);
+ final MongoCollection<Document> collection =
database.getCollection(MongoDbTestConstants.COLLECTION_NAME);
Assertions.assertNotNull(collection);
final Document first = collection.find().first();
Assertions.assertNotNull(first);
diff --git
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AdditionalFieldsTest.java
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAdditionalFieldsTest.java
similarity index 91%
rename from
log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AdditionalFieldsTest.java
rename to
log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAdditionalFieldsTest.java
index 3bb6f0b5f5..c74172925f 100644
---
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AdditionalFieldsTest.java
+++
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAdditionalFieldsTest.java
@@ -14,13 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.mongodb3;
+package org.apache.logging.log4j.mongodb;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import com.mongodb.MongoClient;
import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.apache.logging.log4j.Logger;
@@ -29,18 +29,18 @@ import
org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.bson.Document;
import org.junit.jupiter.api.Test;
-@UsingMongoDb3
+@UsingMongoDb
@LoggerContextSource("log4j2-mongodb-additional-fields.xml")
-public class MongoDb3AdditionalFieldsTest {
+public class MongoDbAdditionalFieldsTest {
@Test
public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger =
ctx.getLogger(MongoDb3AdditionalFieldsTest.class);
+ final Logger logger = ctx.getLogger(MongoDbAdditionalFieldsTest.class);
logger.info("Hello log 1");
logger.info("Hello log 2", new RuntimeException("Hello ex 2"));
- final MongoDatabase database =
mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME);
+ final MongoDatabase database =
mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
assertNotNull(database);
- final MongoCollection<Document> collection =
database.getCollection(MongoDb3TestConstants.COLLECTION_NAME);
+ final MongoCollection<Document> collection =
database.getCollection(MongoDbTestConstants.COLLECTION_NAME);
assertNotNull(collection);
final FindIterable<Document> found = collection.find();
final Document first = found.first();
diff --git
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AuthFailureTest.java
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTest.java
similarity index 85%
rename from
log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AuthFailureTest.java
rename to
log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTest.java
index 847d5c03ff..3247dc28c0 100644
---
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AuthFailureTest.java
+++
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTest.java
@@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.mongodb3;
+package org.apache.logging.log4j.mongodb;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
-import com.mongodb.MongoClient;
+import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.apache.logging.log4j.Logger;
@@ -28,17 +28,17 @@ import
org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.bson.Document;
import org.junit.jupiter.api.Test;
-@UsingMongoDb3
+@UsingMongoDb
@LoggerContextSource("log4j2-mongodb-auth-failure.xml")
-public class MongoDb3AuthFailureTest {
+public class MongoDbAuthFailureTest {
@Test
public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger = ctx.getLogger(MongoDb3AuthFailureTest.class);
+ final Logger logger = ctx.getLogger(MongoDbAuthFailureTest.class);
logger.info("Hello log");
- final MongoDatabase database =
mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME);
+ final MongoDatabase database =
mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
assertNotNull(database);
- final MongoCollection<Document> collection =
database.getCollection(MongoDb3TestConstants.DATABASE_NAME);
+ final MongoCollection<Document> collection =
database.getCollection(MongoDbTestConstants.DATABASE_NAME);
assertNotNull(collection);
final Document first = collection.find().first();
assertNull(first);
diff --git
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3TestConstants.java
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedIntTest.java
similarity index 74%
copy from
log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3TestConstants.java
copy to
log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedIntTest.java
index 1b06fce9f3..500964aff0 100644
---
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3TestConstants.java
+++
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedIntTest.java
@@ -14,11 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.mongodb3;
+package org.apache.logging.log4j.mongodb;
-public class MongoDb3TestConstants {
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
- public static final String PROP_NAME_PORT = "MongoDBTestPort";
- static final String COLLECTION_NAME = "testCollection";
- static final String DATABASE_NAME = "testDb";
+@UsingMongoDb
+@LoggerContextSource("log4j2-mongodb-capped-int.xml")
+public class MongoDbCappedIntTest extends AbstractMongoDbCappedTest {
+
+ // test is in superclass
}
diff --git
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3TestConstants.java
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedLongTest.java
similarity index 74%
copy from
log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3TestConstants.java
copy to
log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedLongTest.java
index 1b06fce9f3..34f921fe7b 100644
---
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3TestConstants.java
+++
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedLongTest.java
@@ -14,11 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.mongodb3;
+package org.apache.logging.log4j.mongodb;
-public class MongoDb3TestConstants {
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
- public static final String PROP_NAME_PORT = "MongoDBTestPort";
- static final String COLLECTION_NAME = "testCollection";
- static final String DATABASE_NAME = "testDb";
+@UsingMongoDb
+@LoggerContextSource("log4j2-mongodb-capped-long.xml")
+public class MongoDbCappedLongTest extends AbstractMongoDbCappedTest {
+
+ // test is in superclass
}
diff --git
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3MapMessageTest.java
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTest.java
similarity index 87%
rename from
log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3MapMessageTest.java
rename to
log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTest.java
index cada31f18b..2733554dbd 100644
---
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3MapMessageTest.java
+++
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTest.java
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.mongodb3;
+package org.apache.logging.log4j.mongodb;
-import com.mongodb.MongoClient;
+import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.apache.logging.log4j.Logger;
@@ -27,20 +27,20 @@ import org.bson.Document;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-@UsingMongoDb3
+@UsingMongoDb
@LoggerContextSource("log4j2-mongodb-map-message.xml")
-public class MongoDb3MapMessageTest {
+public class MongoDbMapMessageTest {
@Test
public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger = ctx.getLogger(MongoDb3MapMessageTest.class);
+ final Logger logger = ctx.getLogger(MongoDbMapMessageTest.class);
final MapMessage<?, Object> mapMessage = new MapMessage<>();
mapMessage.with("SomeName", "SomeValue");
mapMessage.with("SomeInt", 1);
logger.info(mapMessage);
- final MongoDatabase database =
mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME);
+ final MongoDatabase database =
mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
Assertions.assertNotNull(database);
- final MongoCollection<Document> collection =
database.getCollection(MongoDb3TestConstants.COLLECTION_NAME);
+ final MongoCollection<Document> collection =
database.getCollection(MongoDbTestConstants.COLLECTION_NAME);
Assertions.assertNotNull(collection);
final Document first = collection.find().first();
Assertions.assertNotNull(first);
diff --git
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3Resolver.java
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java
similarity index 91%
rename from
log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3Resolver.java
rename to
log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java
index 5df14b9abc..e478ba9bbd 100644
---
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3Resolver.java
+++
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java
@@ -14,9 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.mongodb3;
+package org.apache.logging.log4j.mongodb;
-import com.mongodb.MongoClient;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
import de.flapdoodle.embed.mongo.commands.ServerAddress;
import de.flapdoodle.embed.mongo.distribution.Version;
import de.flapdoodle.embed.mongo.packageresolver.Command;
@@ -37,6 +38,7 @@ import de.flapdoodle.os.OSType;
import de.flapdoodle.reverse.TransitionWalker.ReachedState;
import de.flapdoodle.reverse.transitions.Derive;
import de.flapdoodle.reverse.transitions.Start;
+import java.util.Objects;
import java.util.function.Supplier;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.logging.log4j.Level;
@@ -52,7 +54,7 @@ import
org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;
-public class MongoDb3Resolver extends TypeBasedParameterResolver<MongoClient>
implements BeforeAllCallback {
+public class MongoDbResolver extends TypeBasedParameterResolver<MongoClient>
implements BeforeAllCallback {
private static final Logger LOGGER = StatusLogger.getLogger();
private static final String LOGGING_TARGET_PROPERTY =
"log4j2.mongoDbLoggingTarget";
@@ -75,10 +77,10 @@ public class MongoDb3Resolver extends
TypeBasedParameterResolver<MongoClient> im
default:
}
}
- throw new NotImplementedException(loggingTarget.toString());
+ throw new NotImplementedException(Objects.toString(loggingTarget));
}
- public MongoDb3Resolver() {
+ public MongoDbResolver() {
super(MongoClient.class);
}
@@ -142,11 +144,11 @@ public class MongoDb3Resolver extends
TypeBasedParameterResolver<MongoClient> im
private final MongoClient mongoClient;
public MongoClientHolder(final Mongod mongod, final TestProperties
props) {
- state = mongod.start(Version.Main.V3_6);
+ state = mongod.start(Version.Main.V7_0);
final RunningMongodProcess mongodProcess = state.current();
final ServerAddress addr = mongodProcess.getServerAddress();
- mongoClient = new MongoClient(addr.getHost(), addr.getPort());
- props.setProperty(MongoDb3TestConstants.PROP_NAME_PORT,
addr.getPort());
+ mongoClient = MongoClients.create(String.format("mongodb://%s:%d",
addr.getHost(), addr.getPort()));
+ props.setProperty(MongoDbTestConstants.PROP_NAME_PORT,
addr.getPort());
}
@Override
@@ -169,13 +171,17 @@ public class MongoDb3Resolver extends
TypeBasedParameterResolver<MongoClient> im
this.level = level;
}
+ @Override
public void process(String line) {
LOGGER.log(level, () -> stripLineEndings(line));
}
- public void onProcessed() {}
+ @Override
+ public void onProcessed() {
+ // noop
+ }
- protected String stripLineEndings(String line) {
+ String stripLineEndings(String line) {
// we still need to remove line endings that are passed on by
// StreamToLineProcessor...
return line.replaceAll("[\n\r]+", "");
diff --git
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3ResolverTest.java
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolverTest.java
similarity index 90%
rename from
log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3ResolverTest.java
rename to
log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolverTest.java
index 46c7b2eb16..199cabcb2f 100644
---
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3ResolverTest.java
+++
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolverTest.java
@@ -14,11 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.mongodb3;
+package org.apache.logging.log4j.mongodb;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import com.mongodb.MongoClient;
+import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoIterable;
import org.junit.jupiter.api.Test;
@@ -28,8 +28,8 @@ import org.junit.jupiter.api.Test;
* The test framework {@code de.flapdoodle.embed.mongo} requires Java 8.
* </p>
*/
-@UsingMongoDb3
-public class MongoDb3ResolverTest {
+@UsingMongoDb
+public class MongoDbResolverTest {
@Test
public void testAccess(final MongoClient mongoClient) {
diff --git
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3Test.java
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTest.java
similarity index 89%
rename from
log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3Test.java
rename to
log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTest.java
index 449c0819bf..5c4bbb750c 100644
---
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3Test.java
+++
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTest.java
@@ -14,13 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.mongodb3;
+package org.apache.logging.log4j.mongodb;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import com.mongodb.MongoClient;
import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.apache.logging.log4j.Logger;
@@ -29,18 +29,18 @@ import
org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.bson.Document;
import org.junit.jupiter.api.Test;
-@UsingMongoDb3
+@UsingMongoDb
@LoggerContextSource("log4j2-mongodb.xml")
-public class MongoDb3Test {
+public class MongoDbTest {
@Test
public void test(final LoggerContext ctx, final MongoClient mongoClient) {
- final Logger logger = ctx.getLogger(MongoDb3Test.class);
+ final Logger logger = ctx.getLogger(MongoDbTest.class);
logger.info("Hello log 1");
logger.info("Hello log 2", new RuntimeException("Hello ex 2"));
- final MongoDatabase database =
mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME);
+ final MongoDatabase database =
mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
assertNotNull(database);
- final MongoCollection<Document> collection =
database.getCollection(MongoDb3TestConstants.COLLECTION_NAME);
+ final MongoCollection<Document> collection =
database.getCollection(MongoDbTestConstants.COLLECTION_NAME);
assertNotNull(collection);
final FindIterable<Document> found = collection.find();
final Document first = found.first();
diff --git
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3TestConstants.java
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestConstants.java
similarity index 92%
rename from
log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3TestConstants.java
rename to
log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestConstants.java
index 1b06fce9f3..ed5435599b 100644
---
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3TestConstants.java
+++
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestConstants.java
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.mongodb3;
+package org.apache.logging.log4j.mongodb;
-public class MongoDb3TestConstants {
+public class MongoDbTestConstants {
public static final String PROP_NAME_PORT = "MongoDBTestPort";
static final String COLLECTION_NAME = "testCollection";
diff --git
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/UsingMongoDb3.java
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/UsingMongoDb.java
similarity index 92%
rename from
log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/UsingMongoDb3.java
rename to
log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/UsingMongoDb.java
index 47a5c89f18..8ad70c0d20 100644
---
a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/UsingMongoDb3.java
+++
b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/UsingMongoDb.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.mongodb3;
+package org.apache.logging.log4j.mongodb;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
@@ -32,5 +32,5 @@ import org.junit.jupiter.api.extension.ExtendWith;
@Inherited
@Documented
@ExtendWith(ExtensionContextAnchor.class)
-@ExtendWith(MongoDb3Resolver.class)
-public @interface UsingMongoDb3 {}
+@ExtendWith(MongoDbResolver.class)
+public @interface UsingMongoDb {}
diff --git
a/log4j-mongodb3/src/test/resources/log4j2-mongodb-additional-fields.xml
b/log4j-mongodb/src/test/resources/log4j2-mongodb-additional-fields.xml
similarity index 88%
rename from
log4j-mongodb3/src/test/resources/log4j2-mongodb-additional-fields.xml
rename to log4j-mongodb/src/test/resources/log4j2-mongodb-additional-fields.xml
index e75b9b6f8e..d9d27461a0 100644
--- a/log4j-mongodb3/src/test/resources/log4j2-mongodb-additional-fields.xml
+++ b/log4j-mongodb/src/test/resources/log4j2-mongodb-additional-fields.xml
@@ -15,11 +15,10 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<Configuration status="WARN">
+<Configuration status="TRACE">
<Appenders>
<NoSql name="MongoDbAppender">
- <MongoDb3 databaseName="testDb" collectionName="testCollection"
server="localhost"
- port="${test:MongoDBTestPort:-27017}" />
+ <MongoDb
connection="mongodb://localhost:${test:MongoDBTestPort:-27017}/testDb.testCollection"
/>
<KeyValuePair key="A" value="1" />
<KeyValuePair key="B" value="2" />
<KeyValuePair key="env1" value="${env:PATH}" />
diff --git a/log4j-mongodb3/src/test/resources/log4j2-mongodb-auth-failure.xml
b/log4j-mongodb/src/test/resources/log4j2-mongodb-auth-failure.xml
similarity index 85%
rename from log4j-mongodb3/src/test/resources/log4j2-mongodb-auth-failure.xml
rename to log4j-mongodb/src/test/resources/log4j2-mongodb-auth-failure.xml
index 434c70ceea..e84603a0a5 100644
--- a/log4j-mongodb3/src/test/resources/log4j2-mongodb-auth-failure.xml
+++ b/log4j-mongodb/src/test/resources/log4j2-mongodb-auth-failure.xml
@@ -18,8 +18,8 @@
<Configuration status="WARN">
<Appenders>
<NoSql name="MongoDbAppender">
- <MongoDb3 databaseName="testDb" collectionName="testCollection"
server="localhost" userName="log4jUser" password="12345678"
- port="${test:MongoDBTestPort:-27017}" />
+ <MongoDb
+
connection="mongodb://log4jUser:12345678@localhost:${test:MongoDBTestPort:-27017}/testDb.testCollection"
/>
</NoSql>
</Appenders>
<Loggers>
diff --git a/log4j-mongodb3/src/test/resources/log4j2-mongodb-capped.xml
b/log4j-mongodb/src/test/resources/log4j2-mongodb-capped-int.xml
similarity index 85%
rename from log4j-mongodb3/src/test/resources/log4j2-mongodb-capped.xml
rename to log4j-mongodb/src/test/resources/log4j2-mongodb-capped-int.xml
index b147e8cd5f..746b19914e 100644
--- a/log4j-mongodb3/src/test/resources/log4j2-mongodb-capped.xml
+++ b/log4j-mongodb/src/test/resources/log4j2-mongodb-capped-int.xml
@@ -18,8 +18,10 @@
<Configuration status="WARN">
<Appenders>
<NoSql name="MongoDbAppender">
- <MongoDb3 databaseName="testDb" collectionName="testCollection"
server="localhost" capped="true" collectionSize="1073741824"
- port="${test:MongoDBTestPort:-27017}" />
+ <MongoDb
+
connection="mongodb://localhost:${test:MongoDBTestPort:-27017}/testDb.testCollection"
+ capped="true"
+ collectionSize="1073741824"/>
</NoSql>
</Appenders>
<Loggers>
diff --git a/log4j-mongodb3/src/test/resources/log4j2-mongodb.xml
b/log4j-mongodb/src/test/resources/log4j2-mongodb-capped-long.xml
similarity index 82%
copy from log4j-mongodb3/src/test/resources/log4j2-mongodb.xml
copy to log4j-mongodb/src/test/resources/log4j2-mongodb-capped-long.xml
index d00d48124a..941ea71c4e 100644
--- a/log4j-mongodb3/src/test/resources/log4j2-mongodb.xml
+++ b/log4j-mongodb/src/test/resources/log4j2-mongodb-capped-long.xml
@@ -18,8 +18,11 @@
<Configuration status="WARN">
<Appenders>
<NoSql name="MongoDbAppender">
- <MongoDb3 databaseName="testDb" collectionName="testCollection"
server="localhost"
- port="${test:MongoDBTestPort:-27017}" />
+ <!-- collectionSize="2147483657" is max int + 10 -->
+ <MongoDb
+
connection="mongodb://localhost:${test:MongoDBTestPort:-27017}/testDb.testCollection"
+ capped="true"
+ collectionSize="2147483657"/>
</NoSql>
</Appenders>
<Loggers>
diff --git a/log4j-mongodb3/src/test/resources/log4j2-mongodb-map-message.xml
b/log4j-mongodb/src/test/resources/log4j2-mongodb-map-message.xml
similarity index 88%
rename from log4j-mongodb3/src/test/resources/log4j2-mongodb-map-message.xml
rename to log4j-mongodb/src/test/resources/log4j2-mongodb-map-message.xml
index 16fd4a5d4d..4b740bc947 100644
--- a/log4j-mongodb3/src/test/resources/log4j2-mongodb-map-message.xml
+++ b/log4j-mongodb/src/test/resources/log4j2-mongodb-map-message.xml
@@ -18,8 +18,7 @@
<Configuration status="WARN">
<Appenders>
<NoSql name="MongoDbAppender">
- <MongoDb3 databaseName="testDb" collectionName="testCollection"
server="localhost"
- port="${test:MongoDBTestPort:-27017}" />
+ <MongoDb
connection="mongodb://localhost:${test:MongoDBTestPort:-27017}/testDb.testCollection"
/>
<MessageLayout />
</NoSql>
</Appenders>
diff --git a/log4j-mongodb3/src/test/resources/log4j2-mongodb.xml
b/log4j-mongodb/src/test/resources/log4j2-mongodb.xml
similarity index 88%
rename from log4j-mongodb3/src/test/resources/log4j2-mongodb.xml
rename to log4j-mongodb/src/test/resources/log4j2-mongodb.xml
index d00d48124a..4f0865b2c4 100644
--- a/log4j-mongodb3/src/test/resources/log4j2-mongodb.xml
+++ b/log4j-mongodb/src/test/resources/log4j2-mongodb.xml
@@ -18,8 +18,7 @@
<Configuration status="WARN">
<Appenders>
<NoSql name="MongoDbAppender">
- <MongoDb3 databaseName="testDb" collectionName="testCollection"
server="localhost"
- port="${test:MongoDBTestPort:-27017}" />
+ <MongoDb
connection="mongodb://localhost:${test:MongoDBTestPort:-27017}/testDb.testCollection"
/>
</NoSql>
</Appenders>
<Loggers>
diff --git
a/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/LevelCodec.java
b/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/LevelCodec.java
deleted file mode 100644
index 5e6826d458..0000000000
---
a/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/LevelCodec.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.mongodb3;
-
-import org.apache.logging.log4j.Level;
-import org.bson.BsonReader;
-import org.bson.BsonWriter;
-import org.bson.codecs.Codec;
-import org.bson.codecs.DecoderContext;
-import org.bson.codecs.EncoderContext;
-
-/**
- * A BSON Codec for Log4j {@link Level}s.
- */
-public class LevelCodec implements Codec<Level> {
-
- /**
- * The singleton instance.
- *
- * @since 2.14.0
- */
- public static final LevelCodec INSTANCE = new LevelCodec();
-
- @Override
- public Level decode(final BsonReader reader, final DecoderContext
decoderContext) {
- return Level.getLevel(reader.readString());
- }
-
- @Override
- public void encode(final BsonWriter writer, final Level level, final
EncoderContext encoderContext) {
- writer.writeString(level.name());
- }
-
- @Override
- public Class<Level> getEncoderClass() {
- return Level.class;
- }
-}
diff --git
a/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbConnection.java
b/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbConnection.java
deleted file mode 100644
index ac34650ee4..0000000000
---
a/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbConnection.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.mongodb3;
-
-import com.mongodb.MongoClient;
-import com.mongodb.MongoException;
-import com.mongodb.client.MongoCollection;
-import com.mongodb.client.MongoDatabase;
-import com.mongodb.client.model.CreateCollectionOptions;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.appender.AppenderLoggingException;
-import org.apache.logging.log4j.core.appender.nosql.AbstractNoSqlConnection;
-import org.apache.logging.log4j.core.appender.nosql.NoSqlConnection;
-import org.apache.logging.log4j.core.appender.nosql.NoSqlObject;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.bson.Document;
-
-/**
- * The MongoDB implementation of {@link NoSqlConnection}.
- */
-public final class MongoDbConnection extends AbstractNoSqlConnection<Document,
MongoDbDocumentObject> {
-
- private static final Logger LOGGER = StatusLogger.getLogger();
-
- private static MongoCollection<Document> getOrCreateMongoCollection(
- final MongoDatabase database,
- final String collectionName,
- final boolean isCapped,
- final Integer sizeInBytes) {
- try {
- LOGGER.debug("Gettting collection '{}'...", collectionName);
- // throws IllegalArgumentException if collectionName is invalid
- return database.getCollection(collectionName);
- } catch (final IllegalStateException e) {
- LOGGER.debug("Collection '{}' does not exist.", collectionName);
- final CreateCollectionOptions options = new
CreateCollectionOptions()
- // @formatter:off
- .capped(isCapped)
- .sizeInBytes(sizeInBytes);
- // @formatter:on
- LOGGER.debug(
- "Creating collection {} (capped = {}, sizeInBytes = {})",
collectionName, isCapped, sizeInBytes);
- database.createCollection(collectionName, options);
- return database.getCollection(collectionName);
- }
- }
-
- private final MongoCollection<Document> collection;
- private final MongoClient mongoClient;
-
- public MongoDbConnection(
- final MongoClient mongoClient,
- final MongoDatabase mongoDatabase,
- final String collectionName,
- final boolean isCapped,
- final Integer sizeInBytes) {
- this.mongoClient = mongoClient;
- this.collection = getOrCreateMongoCollection(mongoDatabase,
collectionName, isCapped, sizeInBytes);
- }
-
- @Override
- public void closeImpl() {
- // LOG4J2-1196
- mongoClient.close();
- }
-
- @Override
- public MongoDbDocumentObject[] createList(final int length) {
- return new MongoDbDocumentObject[length];
- }
-
- @Override
- public MongoDbDocumentObject createObject() {
- return new MongoDbDocumentObject();
- }
-
- @Override
- public void insertObject(final NoSqlObject<Document> object) {
- try {
- final Document unwrapped = object.unwrap();
- LOGGER.debug("Inserting object {}", unwrapped);
- this.collection.insertOne(unwrapped);
- } catch (final MongoException e) {
- throw new AppenderLoggingException(
- "Failed to write log event to MongoDB due to error: " +
e.getMessage(), e);
- }
- }
-}
diff --git
a/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbDocumentObject.java
b/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbDocumentObject.java
deleted file mode 100644
index 31798bc2db..0000000000
---
a/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbDocumentObject.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.mongodb3;
-
-import java.util.Arrays;
-import org.apache.logging.log4j.core.appender.nosql.NoSqlObject;
-import org.bson.Document;
-
-/**
- * The MongoDB implementation of {@link NoSqlObject} typed to a BSON {@link
Document}.
- */
-public final class MongoDbDocumentObject implements NoSqlObject<Document> {
-
- private final Document document;
-
- /**
- * Constructs a new instance.
- */
- public MongoDbDocumentObject() {
- this.document = new Document();
- }
-
- @Override
- public void set(final String field, final NoSqlObject<Document> value) {
- this.document.append(field, value != null ? value.unwrap() : null);
- }
-
- @Override
- public void set(final String field, final NoSqlObject<Document>[] values) {
- this.document.append(field, values != null ? Arrays.asList(values) :
null);
- }
-
- @Override
- public void set(final String field, final Object value) {
- this.document.append(field, value);
- }
-
- @Override
- public void set(final String field, final Object[] values) {
- this.document.append(field, values != null ? Arrays.asList(values) :
null);
- }
-
- @Override
- public Document unwrap() {
- return this.document;
- }
-}
diff --git
a/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbDocumentObjectCodec.java
b/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbDocumentObjectCodec.java
deleted file mode 100644
index 812ca96ee3..0000000000
---
a/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbDocumentObjectCodec.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.mongodb3;
-
-import org.bson.BsonReader;
-import org.bson.BsonWriter;
-import org.bson.Document;
-import org.bson.codecs.Codec;
-import org.bson.codecs.DecoderContext;
-import org.bson.codecs.DocumentCodec;
-import org.bson.codecs.EncoderContext;
-
-final class MongoDbDocumentObjectCodec implements Codec<MongoDbDocumentObject>
{
-
- private final Codec<Document> documentCodec = new DocumentCodec();
-
- @Override
- public void encode(
- final BsonWriter writer, final MongoDbDocumentObject value, final
EncoderContext encoderContext) {
- documentCodec.encode(writer, value.unwrap(), encoderContext);
- }
-
- @Override
- public Class<MongoDbDocumentObject> getEncoderClass() {
- return MongoDbDocumentObject.class;
- }
-
- @Override
- public MongoDbDocumentObject decode(final BsonReader reader, final
DecoderContext decoderContext) {
- final MongoDbDocumentObject object = new MongoDbDocumentObject();
- documentCodec.decode(reader, decoderContext).entrySet().stream()
- .forEach(entry -> object.set(entry.getKey(),
entry.getValue()));
- return object;
- }
-}
diff --git
a/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbProvider.java
b/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbProvider.java
deleted file mode 100644
index 90a9a6f492..0000000000
---
a/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbProvider.java
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- * 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.mongodb3;
-
-import com.mongodb.MongoClient;
-import com.mongodb.MongoClientOptions;
-import com.mongodb.MongoCredential;
-import com.mongodb.ServerAddress;
-import com.mongodb.WriteConcern;
-import com.mongodb.client.MongoDatabase;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.Core;
-import org.apache.logging.log4j.core.appender.nosql.NoSqlProvider;
-import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
-import org.apache.logging.log4j.core.config.plugins.convert.TypeConverters;
-import
org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
-import
org.apache.logging.log4j.core.config.plugins.validation.constraints.ValidHost;
-import
org.apache.logging.log4j.core.config.plugins.validation.constraints.ValidPort;
-import org.apache.logging.log4j.core.filter.AbstractFilterable;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.util.LoaderUtil;
-import org.apache.logging.log4j.util.Strings;
-import org.bson.codecs.configuration.CodecRegistries;
-import org.bson.codecs.configuration.CodecRegistry;
-
-/**
- * The MongoDB implementation of {@link NoSqlProvider}.using the MongoDB
driver version 3 API.
- */
-@Plugin(name = "MongoDb3", category = Core.CATEGORY_NAME, printObject = true)
-public final class MongoDbProvider implements NoSqlProvider<MongoDbConnection>
{
-
- public static class Builder<B extends Builder<B>> extends
AbstractFilterable.Builder<B>
- implements
org.apache.logging.log4j.core.util.Builder<MongoDbProvider> {
-
- // @formatter:off
- private static final CodecRegistry CODEC_REGISTRIES =
CodecRegistries.fromRegistries(
- MongoClient.getDefaultCodecRegistry(),
- CodecRegistries.fromCodecs(LevelCodec.INSTANCE),
- CodecRegistries.fromCodecs(new MongoDbDocumentObjectCodec()));
- // @formatter:on
-
- private static WriteConcern toWriteConcern(
- final String writeConcernConstant, final String
writeConcernConstantClassName) {
- WriteConcern writeConcern;
- if (Strings.isNotEmpty(writeConcernConstant)) {
- if (Strings.isNotEmpty(writeConcernConstantClassName)) {
- try {
- final Class<?> writeConcernConstantClass =
LoaderUtil.loadClass(writeConcernConstantClassName);
- final Field field =
writeConcernConstantClass.getField(writeConcernConstant);
- writeConcern = (WriteConcern) field.get(null);
- } catch (final Exception e) {
- LOGGER.error(
- "Write concern constant [{}.{}] not found,
using default.",
- writeConcernConstantClassName,
- writeConcernConstant);
- writeConcern = DEFAULT_WRITE_CONCERN;
- }
- } else {
- writeConcern = WriteConcern.valueOf(writeConcernConstant);
- if (writeConcern == null) {
- LOGGER.warn("Write concern constant [{}] not found,
using default.", writeConcernConstant);
- writeConcern = DEFAULT_WRITE_CONCERN;
- }
- }
- } else {
- writeConcern = DEFAULT_WRITE_CONCERN;
- }
- return writeConcern;
- }
-
- @PluginBuilderAttribute
- @Required(message = "No collection name provided")
- private String collectionName;
-
- @PluginBuilderAttribute
- private int collectionSize = DEFAULT_COLLECTION_SIZE;
-
- @PluginBuilderAttribute
- @Required(message = "No database name provided")
- private String databaseName;
-
- @PluginBuilderAttribute
- private String factoryClassName;
-
- @PluginBuilderAttribute
- private String factoryMethodName;
-
- @PluginBuilderAttribute("capped")
- private boolean capped = false;
-
- @PluginBuilderAttribute(sensitive = true)
- private String password;
-
- @PluginBuilderAttribute
- @ValidPort
- private String port = "" + DEFAULT_PORT;
-
- @PluginBuilderAttribute
- @ValidHost
- private String server = "localhost";
-
- @PluginBuilderAttribute
- private String userName;
-
- @PluginBuilderAttribute
- private String writeConcernConstant;
-
- @PluginBuilderAttribute
- private String writeConcernConstantClassName;
-
- @SuppressWarnings("resource")
- @Override
- public MongoDbProvider build() {
- MongoDatabase database;
- String description;
- MongoClient mongoClient = null;
-
- if (Strings.isNotEmpty(factoryClassName) &&
Strings.isNotEmpty(factoryMethodName)) {
- try {
- final Class<?> factoryClass =
LoaderUtil.loadClass(factoryClassName);
- final Method method =
factoryClass.getMethod(factoryMethodName);
- final Object object = method.invoke(null);
-
- if (object instanceof MongoDatabase) {
- database = (MongoDatabase) object;
- } else if (object instanceof MongoClient) {
- if (Strings.isNotEmpty(databaseName)) {
- database = ((MongoClient)
object).getDatabase(databaseName);
- } else {
- LOGGER.error(
- "The factory method [{}.{}()] returned a
MongoClient so the database name is "
- + "required.",
- factoryClassName,
- factoryMethodName);
- return null;
- }
- } else {
- if (object == null) {
- LOGGER.error(
- "The factory method [{}.{}()] returned
null.", factoryClassName, factoryMethodName);
- } else {
- LOGGER.error(
- "The factory method [{}.{}()] returned an
unsupported type [{}].",
- factoryClassName,
- factoryMethodName,
- object.getClass().getName());
- }
- return null;
- }
-
- final String databaseName = database.getName();
- description = "database=" + databaseName;
- } catch (final ClassNotFoundException e) {
- LOGGER.error("The factory class [{}] could not be
loaded.", factoryClassName, e);
- return null;
- } catch (final NoSuchMethodException e) {
- LOGGER.error(
- "The factory class [{}] does not have a no-arg
method named [{}].",
- factoryClassName,
- factoryMethodName,
- e);
- return null;
- } catch (final Exception e) {
- LOGGER.error(
- "The factory method [{}.{}()] could not be
invoked.",
- factoryClassName,
- factoryMethodName,
- e);
- return null;
- }
- } else if (Strings.isNotEmpty(databaseName)) {
- MongoCredential mongoCredential = null;
- description = "database=" + databaseName;
- if (Strings.isNotEmpty(userName) &&
Strings.isNotEmpty(password)) {
- description += ", username=" + userName;
- mongoCredential =
MongoCredential.createCredential(userName, databaseName,
password.toCharArray());
- }
- try {
- final int portInt = TypeConverters.convert(port,
int.class, DEFAULT_PORT);
- description += ", server=" + server + ", port=" + portInt;
- final WriteConcern writeConcern =
- toWriteConcern(writeConcernConstant,
writeConcernConstantClassName);
- // @formatter:off
- final MongoClientOptions options =
MongoClientOptions.builder()
- .codecRegistry(CODEC_REGISTRIES)
- .writeConcern(writeConcern)
- .build();
- // @formatter:on
- final ServerAddress serverAddress = new
ServerAddress(server, portInt);
- mongoClient = mongoCredential == null
- ?
- // @formatter:off
- new MongoClient(serverAddress, options)
- : new MongoClient(serverAddress, mongoCredential,
options);
- // @formatter:on
- database = mongoClient.getDatabase(databaseName);
- } catch (final Exception e) {
- LOGGER.error(
- "Failed to obtain a database instance from the
MongoClient at server [{}] and "
- + "port [{}].",
- server,
- port);
- close(mongoClient);
- return null;
- }
- } else {
- LOGGER.error("No factory method was provided so the database
name is required.");
- close(mongoClient);
- return null;
- }
-
- try {
- database.listCollectionNames().first(); // Check if the
database actually requires authentication
- } catch (final Exception e) {
- LOGGER.error(
- "The database is not up, or you are not authenticated,
try supplying a username and password to the MongoDB provider.",
- e);
- close(mongoClient);
- return null;
- }
-
- return new MongoDbProvider(mongoClient, database, collectionName,
capped, collectionSize, description);
- }
-
- private void close(final MongoClient mongoClient) {
- if (mongoClient != null) {
- mongoClient.close();
- }
- }
-
- public B setCapped(final boolean isCapped) {
- this.capped = isCapped;
- return asBuilder();
- }
-
- public B setCollectionName(final String collectionName) {
- this.collectionName = collectionName;
- return asBuilder();
- }
-
- public B setCollectionSize(final int collectionSize) {
- this.collectionSize = collectionSize;
- return asBuilder();
- }
-
- public B setDatabaseName(final String databaseName) {
- this.databaseName = databaseName;
- return asBuilder();
- }
-
- public B setFactoryClassName(final String factoryClassName) {
- this.factoryClassName = factoryClassName;
- return asBuilder();
- }
-
- public B setFactoryMethodName(final String factoryMethodName) {
- this.factoryMethodName = factoryMethodName;
- return asBuilder();
- }
-
- public B setPassword(final String password) {
- this.password = password;
- return asBuilder();
- }
-
- public B setPort(final String port) {
- this.port = port;
- return asBuilder();
- }
-
- public B setServer(final String server) {
- this.server = server;
- return asBuilder();
- }
-
- public B setUserName(final String userName) {
- this.userName = userName;
- return asBuilder();
- }
-
- public B setWriteConcernConstant(final String writeConcernConstant) {
- this.writeConcernConstant = writeConcernConstant;
- return asBuilder();
- }
-
- public B setWriteConcernConstantClassName(final String
writeConcernConstantClassName) {
- this.writeConcernConstantClassName = writeConcernConstantClassName;
- return asBuilder();
- }
- }
-
- private static final int DEFAULT_COLLECTION_SIZE = 536870912;
- private static final int DEFAULT_PORT = 27017;
- private static final WriteConcern DEFAULT_WRITE_CONCERN =
WriteConcern.ACKNOWLEDGED;
-
- private static final Logger LOGGER = StatusLogger.getLogger();
-
- @PluginBuilderFactory
- public static <B extends Builder<B>> B newBuilder() {
- return new Builder<B>().asBuilder();
- }
-
- private final String collectionName;
- private final Integer collectionSize;
- private final String description;
- private final boolean isCapped;
- private final MongoClient mongoClient;
- private final MongoDatabase mongoDatabase;
-
- private MongoDbProvider(
- final MongoClient mongoClient,
- final MongoDatabase mongoDatabase,
- final String collectionName,
- final boolean isCapped,
- final Integer collectionSize,
- final String description) {
- this.mongoClient = mongoClient;
- this.mongoDatabase = mongoDatabase;
- this.collectionName = collectionName;
- this.isCapped = isCapped;
- this.collectionSize = collectionSize;
- this.description = "mongoDb{ " + description + " }";
- }
-
- @Override
- public MongoDbConnection getConnection() {
- return new MongoDbConnection(mongoClient, mongoDatabase,
collectionName, isCapped, collectionSize);
- }
-
- @Override
- public String toString() {
- return description;
- }
-}
diff --git
a/log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4Provider.java
b/log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4Provider.java
index 171b4d296c..299e369630 100644
---
a/log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4Provider.java
+++
b/log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4Provider.java
@@ -37,9 +37,11 @@ import org.bson.codecs.configuration.CodecRegistry;
* The MongoDB implementation of {@link NoSqlProvider} using the MongoDB driver
* version 4 API.
*/
-@Plugin(name = "MongoDb4", category = Core.CATEGORY_NAME, printObject = true)
+@Plugin(name = MongoDb4Provider.PLUGIN_NAME, category = Core.CATEGORY_NAME,
printObject = true)
public final class MongoDb4Provider implements
NoSqlProvider<MongoDb4Connection> {
+ static final String PLUGIN_NAME = "MongoDb4";
+
public static class Builder<B extends Builder<B>> extends
AbstractFilterable.Builder<B>
implements
org.apache.logging.log4j.core.util.Builder<MongoDb4Provider> {
@@ -55,6 +57,7 @@ public final class MongoDb4Provider implements
NoSqlProvider<MongoDb4Connection>
@Override
public MongoDb4Provider build() {
+ StatusLogger.getLogger().warn("The {} Appender is deprecated, use
the MongoDb Appender.", PLUGIN_NAME);
return new MongoDb4Provider(connectionStringSource, capped,
collectionSize);
}
diff --git
a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Resolver.java
b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Resolver.java
index fe4a4c18a2..da937eb3ec 100644
---
a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Resolver.java
+++
b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Resolver.java
@@ -146,7 +146,7 @@ public class MongoDb4Resolver extends
TypeBasedParameterResolver<MongoClient> im
private final MongoClient mongoClient;
public MongoClientHolder(final Mongod mongod, final TestProperties
props) {
- state = mongod.start(Version.Main.V4_4);
+ state = mongod.start(Version.Main.V7_0);
final RunningMongodProcess mongodProcess = state.current();
final ServerAddress addr = mongodProcess.getServerAddress();
mongoClient = MongoClients.create(String.format("mongodb://%s:%d",
addr.getHost(), addr.getPort()));
diff --git a/pom.xml b/pom.xml
index 5a94c774d9..65e6723903 100644
--- a/pom.xml
+++ b/pom.xml
@@ -257,7 +257,7 @@
<module>log4j-jul</module>
<module>log4j-layout-template-json</module>
<module>log4j-layout-template-json-test</module>
- <module>log4j-mongodb3</module>
+ <module>log4j-mongodb</module>
<module>log4j-mongodb4</module>
<module>log4j-osgi-test</module>
<module>log4j-perf-test</module>
@@ -467,13 +467,13 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-mongodb3</artifactId>
+ <artifactId>log4j-mongodb4</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-mongodb4</artifactId>
+ <artifactId>log4j-mongodb</artifactId>
<version>${project.version}</version>
</dependency>
diff --git a/src/changelog/.2.x.x/add_log4j_mongodb.xml
b/src/changelog/.2.x.x/add_log4j_mongodb.xml
new file mode 100644
index 0000000000..8227ff3d54
--- /dev/null
+++ b/src/changelog/.2.x.x/add_log4j_mongodb.xml
@@ -0,0 +1,7 @@
+<?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="updated">
+ <description format="asciidoc">Add module log4j-mongodb to track the current
MongoDB driver (currently version 5).</description>
+</entry>
diff --git a/src/changelog/.2.x.x/deprecate_log4j_mongodb4.xml
b/src/changelog/.2.x.x/deprecate_log4j_mongodb4.xml
new file mode 100644
index 0000000000..e83cd2e7f1
--- /dev/null
+++ b/src/changelog/.2.x.x/deprecate_log4j_mongodb4.xml
@@ -0,0 +1,7 @@
+<?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="updated">
+ <description format="asciidoc">Deprecate the log4j-mongodb4 module in favor
of log4j-mongodb.</description>
+</entry>
diff --git a/src/changelog/.2.x.x/remove_log4j_mongodb3.xml
b/src/changelog/.2.x.x/remove_log4j_mongodb3.xml
new file mode 100644
index 0000000000..310e97f51b
--- /dev/null
+++ b/src/changelog/.2.x.x/remove_log4j_mongodb3.xml
@@ -0,0 +1,7 @@
+<?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="updated">
+ <description format="asciidoc">Remove module log4j-mongodb3, use
log4j-mongodb instead, log4j-mongodb4 is deprecated for removal.</description>
+</entry>
diff --git a/src/site/antora/modules/ROOT/pages/manual/appenders.adoc
b/src/site/antora/modules/ROOT/pages/manual/appenders.adoc
index 980dac7c52..f473f73483 100644
--- a/src/site/antora/modules/ROOT/pages/manual/appenders.adoc
+++ b/src/site/antora/modules/ROOT/pages/manual/appenders.adoc
@@ -1919,96 +1919,61 @@ databases if represented in a JSON format:
}
----
-[#NoSQLAppenderMongoDB]
-== NoSQLAppenderMongoDB
+[#NoSQLAppenderMongoDBMain]
+== NoSQL Appenders for MongoDB
Starting with Log4 2.11.0, we provide the following MongoDB modules:
-* Added in v2.11.0, dropped in v2.14.0: `log4j-mongodb2` defines the
configuration element MongoDb2 matching the MongoDB Driver version 2.
-* Added in v2.11.0: `log4j-mongodb3` defines the configuration element
MongoDb3 matching the MongoDB Driver version 3.
-* Added in 2.14.0: `log4j-mongodb4` defines the configuration element
-link:#NoSQLAppenderMongoDB4[`MongoDb4`] matching the MongoDB Driver
-version 4.
+* Added in 2.11.0, removed in 2.14.0: `log4j-mongodb2` defines the
configuration element MongoDb2 matching the MongoDB Driver version 2.
+* Added in 2.11.0, removed in 2.24.0: `log4j-mongodb3` defines the
configuration element MongoDb3 matching the MongoDB Driver version 3.
+* Added in 2.14.0, deprecated in 2.24.0: `log4j-mongodb4` defines the
configuration element
+link:#NoSQLAppenderMongoDB4[`MongoDb4`] matching the MongoDB Driver version 4.
+* Added in 2.24.0: `log4j-mongodb` defines the configuration element
+link:#NoSQLAppenderMongoDBCurrent[`MongoDb`] matching the current MongoDB
Driver (version 5). This module tracks the current MongoDB Driver.
-We no longer provide the modules `log4j-mongodb`.
+[#NoSQLAppenderMongoDBCurrent]
+== NoSQL Appender for MongoDB
-The module `log4j-mongodb2` aliases the old configuration element `MongoDb` to
`MongoDb2`.
-
-[[NoSQLAppenderMongoDB3]]
-== NoSQLAppender for MongoDB 3
-
-This section details specializations of the link:#NoSQLAppender[NoSQLAppender]
provider for MongoDB using the MongoDB driver version 3. The NoSQLAppender
Appender writes log events to a NoSQL database using an internal lightweight
provider interface.
+This section details specializations of the
+link:#NoSQLAppender[NoSQLAppender] provider for MongoDB using the
+current MongoDB driver (version 5). The NoSQLAppender Appender writes log
events
+to a NoSQL database using an internal lightweight provider interface.
-[width="100%",options="header"]
-|===
+.MongoDB Provider Parameters
+[cols="20%,20%,60%",options="header",]
+|=======================================================================
|Parameter Name |Type |Description
+|connection |String |_Required._ The MongoDB
+http://mongodb.github.io/mongo-java-driver/5.0/apidocs/mongodb-driver-core/com/mongodb/ConnectionString.html?is-external=true"[connection
string]
+in the format
`mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database.collection][?options]]`.
-|collectionName
-|String
-|_Required._ The name of the MongoDB collection to insert the events into.
-
-|writeConcernConstant
-|Field
-|By default, the MongoDB provider inserts records with the instructions
`com.mongodb.WriteConcern.ACKNOWLEDGED`. Use this optional attribute to specify
the name of a constant other than `ACKNOWLEDGED`.
-
-|writeConcernConstantClass
-|Class
-|If you specify `writeConcernConstant`, you can use this attribute to specify
a class other than `com.mongodb.WriteConcern` to find the constant on (to
create your own custom instructions).
-
-|factoryClassName
-|Class
-|To provide a connection to the MongoDB database, you can use this attribute
and `factoryMethodName` to specify a class and static method to get the
connection from. The method must return a `com.mongodb.client.MongoDatabase` or
a `com.mongodb.MongoClient`. If the `com.mongodb.client.MongoDatabase` is not
authenticated, you must also specify a `username` and `password`. If you use
the factory method for providing a connection, you must not specify the
`databaseName`, `server`, or `port` [...]
-
-|factoryMethodName
-|Method
-|See the documentation for attribute `factoryClassName`.
-
-|databaseName
-|String
-|If you do not specify a `factoryClassName` and `factoryMethodName` for
providing a MongoDB connection, you must specify a MongoDB database name using
this attribute. You must also specify a `username` and `password`. You can
optionally also specify a `server` (defaults to localhost), and a `port`
(defaults to the default MongoDB port).
-
-|server
-|String
-|See the documentation for attribute `databaseName`.
-
-|port
-|int
-|See the documentation for attribute `databaseName`.
-
-|username
-|String
-|See the documentation for attributes `databaseName` and `factoryClassName`.
-
-|password
-|String
-|See the documentation for attributes `databaseName` and `factoryClassName`.
-
-|capped
-|boolean
-|Enable support for
https://docs.mongodb.com/manual/core/capped-collections/[capped collections].
+|capped |boolean |Enable support for
+https://docs.mongodb.com/manual/core/capped-collections/[capped
+collections]
-|collectionSize
-|int
-|Specify the size in bytes of the capped collection to use if enabled. The
minimum size is 4096 bytes, and larger sizes will be increased to the nearest
integer multiple of 256. See the capped collection documentation linked above
for more information.
-|===
+|collectionSize |long |Specify the size in bytes of the capped collection
+to use if enabled. The minimum size is 4096 bytes, and larger sizes will
+be increased to the nearest integer multiple of 256. See the capped
+collection documentation linked above for more information.
+|=======================================================================
This appender is xref:manual/messages.adoc#MapMessage[MapMessage]-aware.
-Here are a few sample configurations for the NoSQLAppender and MongoDB3
provider:
+Here are a few sample configurations for the NoSQLAppender and MongoDB4
+provider:
[source,xml]
----
<?xml version="1.0" encoding="UTF-8"?>
-<Configuration status="error">
+<Configuration status="WARN">
<Appenders>
- <NoSql name="databaseAppender">
- <MongoDb3 databaseName="applicationDb" collectionName="applicationLog"
server="mongo.example.org"
- username="loggingUser" password="abc123" />
+ <NoSql name="MongoDbAppender">
+ <MongoDb
connection="mongodb://log4jUser:12345678@localhost:${sys:MongoDBTestPort:-27017}/testDb.testCollection"
/>
</NoSql>
</Appenders>
<Loggers>
- <Root level="warn">
- <AppenderRef ref="databaseAppender"/>
+ <Root level="ALL">
+ <AppenderRef ref="MongoDbAppender" />
</Root>
</Loggers>
</Configuration>
@@ -2017,47 +1982,50 @@ Here are a few sample configurations for the
NoSQLAppender and MongoDB3 provider
[source,xml]
----
<?xml version="1.0" encoding="UTF-8"?>
-<Configuration status="error">
+<Configuration status="WARN">
<Appenders>
- <NoSql name="databaseAppender">
- <MongoDb3 collectionName="applicationLog"
factoryClassName="org.example.db.ConnectionFactory"
- factoryMethodName="getNewMongoClient" />
+ <NoSql name="MongoDbAppender">
+ <MongoDb
+
connection="mongodb://localhost:${sys:MongoDBTestPort:-27017}/testDb.testCollection"
+ capped="true"
+ collectionSize="1073741824"/>
</NoSql>
</Appenders>
<Loggers>
- <Root level="warn">
- <AppenderRef ref="databaseAppender"/>
+ <Root level="ALL">
+ <AppenderRef ref="MongoDbAppender" />
</Root>
</Loggers>
</Configuration>
----
-You can define additional fields to log using `KeyValuePair` elements, for
example:
+You can define additional fields to log using KeyValuePair elements, for
example:
[source,xml]
----
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
- <Appenders>
- <NoSql name="MongoDbAppender">
- <MongoDb3 databaseName="testDb" collectionName="testCollection"
server="localhost"
- port="${sys:MongoDBTestPort:-27017}" />
- <KeyValuePair key="A" value="1" />
- <KeyValuePair key="B" value="2" />
- <KeyValuePair key="env1" value="${env:PATH}" />
- <KeyValuePair key="env2" value="$${env:PATH}" />
- </NoSql>
- </Appenders>
- <Loggers>
- <Root level="ALL">
- <AppenderRef ref="MongoDbAppender" />
- </Root>
- </Loggers>
+ <Appenders>
+ <NoSql name="MongoDbAppender">
+ <MongoDb
connection="mongodb://localhost:${sys:MongoDBTestPort:-27017}/testDb.testCollection"
/>
+ <KeyValuePair key="A" value="1" />
+ <KeyValuePair key="B" value="2" />
+ <KeyValuePair key="env1" value="${env:PATH}" />
+ <KeyValuePair key="env2" value="$${env:PATH}" />
+ </NoSql>
+ </Appenders>
+ <Loggers>
+ <Root level="ALL">
+ <AppenderRef ref="MongoDbAppender" />
+ </Root>
+ </Loggers>
</Configuration>
----
[#NoSQLAppenderMongoDB4]
-== NoSQLAppenderMongoDB4
+== (Deprecated) No SQLAppender for MongoDB 4
+
+The `log4j-mongodb4` module is deprecated in favor of
link:#NoSQLAppenderMongoDBCurrent[NoSQLAppender for MongoDB].
This section details specializations of the
link:#NoSQLAppender[NoSQLAppender] provider for MongoDB using the
diff --git a/src/site/antora/modules/ROOT/pages/manual/messages.adoc
b/src/site/antora/modules/ROOT/pages/manual/messages.adoc
index 7769192eb8..8f2128f430 100644
--- a/src/site/antora/modules/ROOT/pages/manual/messages.adoc
+++ b/src/site/antora/modules/ROOT/pages/manual/messages.adoc
@@ -225,7 +225,7 @@ with a no layout, it converts a Log4j `MapMessage` to a JMS
* When a xref:manual/appenders.adoc#JDBCAppender[JDBC Appender] is configured
with no layout, it converts a Log4j `MapMessage` to values in a
SQL INSERT statement.
-* When a xref:manual/appenders.adoc#NoSQLAppenderMongoDB4[MongoDB4 Appender] is
+* When a xref:manual/appenders.adoc#NoSQLAppenderMongoDBMain[MongoDB Appender]
is
configured with no layout, it converts a Log4j `MapMessage` to
fields in a MongoDB object.