From e12c57cc10277ead48daa5c7362dfdd51769251b Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 17 Apr 2024 22:57:28 -0400 Subject: [PATCH 1/9] 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. --- .../.log4j-plugin-processing-activator | 1 + log4j-mongodb/pom.xml | 150 ++++++++++++++ .../log4j/mongodb/MongoDbProvider.java | 46 +++++ .../logging/log4j/mongodb/package-info.java | 28 +++ .../mongodb/AbstractMongoDbCappedTest.java | 42 ++++ .../mongodb/MongoDbAdditionalFieldsTest.java | 74 +++++++ .../log4j/mongodb/MongoDbAuthFailureTest.java | 46 +++++ .../log4j/mongodb/MongoDbCappedIntTest.java | 26 +++ .../log4j/mongodb/MongoDbCappedLongTest.java | 26 +++ .../log4j/mongodb/MongoDbMapMessageTest.java | 51 +++++ .../log4j/mongodb/MongoDbResolver.java | 190 ++++++++++++++++++ .../log4j/mongodb/MongoDbResolverTest.java | 40 ++++ .../logging/log4j/mongodb/MongoDbTest.java | 59 ++++++ .../log4j/mongodb/MongoDbTestConstants.java | 24 +++ .../logging/log4j/mongodb/UsingMongoDb.java | 36 ++++ .../log4j2-mongodb-additional-fields.xml | 33 +++ .../resources/log4j2-mongodb-auth-failure.xml | 30 +++ .../resources/log4j2-mongodb-capped-int.xml | 32 +++ .../resources/log4j2-mongodb-capped-long.xml | 33 +++ .../resources/log4j2-mongodb-map-message.xml | 30 +++ .../src/test/resources/log4j2-mongodb.xml | 29 +++ pom.xml | 1 + src/changelog/.2.x.x/add_log4j_mongodb.xml | 8 + .../modules/ROOT/pages/manual/appenders.adoc | 98 ++++++++- 24 files changed, 1128 insertions(+), 5 deletions(-) create mode 100644 log4j-mongodb/.log4j-plugin-processing-activator create mode 100644 log4j-mongodb/pom.xml create mode 100644 log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbProvider.java create mode 100644 log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/package-info.java create mode 100644 log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/AbstractMongoDbCappedTest.java create mode 100644 log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAdditionalFieldsTest.java create mode 100644 log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTest.java create mode 100644 log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedIntTest.java create mode 100644 log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedLongTest.java create mode 100644 log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTest.java create mode 100644 log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java create mode 100644 log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolverTest.java create mode 100644 log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTest.java create mode 100644 log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestConstants.java create mode 100644 log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/UsingMongoDb.java create mode 100644 log4j-mongodb/src/test/resources/log4j2-mongodb-additional-fields.xml create mode 100644 log4j-mongodb/src/test/resources/log4j2-mongodb-auth-failure.xml create mode 100644 log4j-mongodb/src/test/resources/log4j2-mongodb-capped-int.xml create mode 100644 log4j-mongodb/src/test/resources/log4j2-mongodb-capped-long.xml create mode 100644 log4j-mongodb/src/test/resources/log4j2-mongodb-map-message.xml create mode 100644 log4j-mongodb/src/test/resources/log4j2-mongodb.xml create mode 100644 src/changelog/.2.x.x/add_log4j_mongodb.xml diff --git a/log4j-mongodb/.log4j-plugin-processing-activator b/log4j-mongodb/.log4j-plugin-processing-activator new file mode 100644 index 00000000000..ba133f36961 --- /dev/null +++ b/log4j-mongodb/.log4j-plugin-processing-activator @@ -0,0 +1 @@ +This file is here to activate the `plugin-processing` Maven profile. diff --git a/log4j-mongodb/pom.xml b/log4j-mongodb/pom.xml new file mode 100644 index 00000000000..dd3b68facc6 --- /dev/null +++ b/log4j-mongodb/pom.xml @@ -0,0 +1,150 @@ + + + + 4.0.0 + + org.apache.logging.log4j + log4j + ${revision} + ../log4j-parent + + log4j-mongodb + Apache Log4j MongoDB Appender + MongoDB appender for Log4j using the MongoDB 5 driver API. + + + org.apache.logging.log4j.core + + 5.0.1 + + false + true + + + + + org.mongodb + bson + ${mongodb5.version} + + + org.mongodb + mongodb-driver-core + ${mongodb5.version} + + + org.mongodb + mongodb-driver-legacy + ${mongodb5.version} + + + org.mongodb + mongodb-driver-sync + ${mongodb5.version} + + + + + + org.apache.logging.log4j + log4j-api + + + org.apache.logging.log4j + log4j-mongodb4 + + + org.mongodb + bson + + + org.mongodb + mongodb-driver-core + + + org.mongodb + mongodb-driver-sync + + + org.apache.logging.log4j + log4j-api-test + test + + + junit + junit + + + + + org.apache.logging.log4j + log4j-core-test + test + + + junit + junit + + + + + org.apache.commons + commons-lang3 + test + + + de.flapdoodle.embed + de.flapdoodle.embed.mongo + test + + + de.flapdoodle.embed + de.flapdoodle.embed.process + test + + + de.flapdoodle.reverse + de.flapdoodle.reverse + test + + + org.junit.jupiter + junit-jupiter-api + test + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + 1 + + + + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter.version} + + + + + + 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 00000000000..0828b16648a --- /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 { + + private MongoDbProvider() {} + + @PluginBuilderFactory + public static > B newBuilder() { + return MongoDb4Provider.newBuilder(); + } +} diff --git a/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/package-info.java b/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/package-info.java new file mode 100644 index 00000000000..7e8d5c80531 --- /dev/null +++ b/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/package-info.java @@ -0,0 +1,28 @@ +/* + * 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. + */ +/** + * The classes in this package contain the MongoDB provider for the NoSQL + * Appender. + */ +@Export +@Open("org.apache.logging.log4j.core") +@Version("2.21.0") +package org.apache.logging.log4j.mongodb; + +import aQute.bnd.annotation.jpms.Open; +import org.osgi.annotation.bundle.Export; +import org.osgi.annotation.versioning.Version; diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/AbstractMongoDbCappedTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/AbstractMongoDbCappedTest.java new file mode 100644 index 00000000000..07e39339941 --- /dev/null +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/AbstractMongoDbCappedTest.java @@ -0,0 +1,42 @@ +/* + * 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 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.bson.Document; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public abstract class AbstractMongoDbCappedTest { + + @Test + public void test(final LoggerContext ctx, final MongoClient mongoClient) { + final Logger logger = ctx.getLogger(AbstractMongoDbCappedTest.class); + logger.info("Hello log"); + final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME); + Assertions.assertNotNull(database); + final MongoCollection collection = database.getCollection(MongoDbTestConstants.COLLECTION_NAME); + Assertions.assertNotNull(collection); + final Document first = collection.find().first(); + Assertions.assertNotNull(first); + Assertions.assertEquals("Hello log", first.getString("message"), first.toJson()); + } +} diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAdditionalFieldsTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAdditionalFieldsTest.java new file mode 100644 index 00000000000..c74172925f5 --- /dev/null +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAdditionalFieldsTest.java @@ -0,0 +1,74 @@ +/* + * 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 static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +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; +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.Test; + +@UsingMongoDb +@LoggerContextSource("log4j2-mongodb-additional-fields.xml") +public class MongoDbAdditionalFieldsTest { + + @Test + public void test(final LoggerContext ctx, final MongoClient mongoClient) { + 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(MongoDbTestConstants.DATABASE_NAME); + assertNotNull(database); + final MongoCollection collection = database.getCollection(MongoDbTestConstants.COLLECTION_NAME); + assertNotNull(collection); + final FindIterable found = collection.find(); + final Document first = found.first(); + assertNotNull(first, "first"); + assertEquals("Hello log 1", first.getString("message"), first.toJson()); + assertEquals("INFO", first.getString("level"), first.toJson()); + // + Document list; + final String envPath = System.getenv("PATH"); + // + list = first.get("additionalFields", Document.class); + assertEquals("1", list.getString("A"), first.toJson()); + assertEquals("2", list.getString("B"), first.toJson()); + assertEquals(envPath, list.getString("env1"), first.toJson()); + assertEquals(envPath, list.getString("env2"), first.toJson()); + // + found.skip(1); + final Document second = found.first(); + assertNotNull(second); + assertEquals("Hello log 2", second.getString("message"), second.toJson()); + assertEquals("INFO", second.getString("level"), second.toJson()); + final Document thrown = second.get("thrown", Document.class); + assertEquals("Hello ex 2", thrown.getString("message"), thrown.toJson()); + // + list = second.get("additionalFields", Document.class); + assertEquals("1", list.getString("A"), first.toJson()); + assertEquals("2", list.getString("B"), first.toJson()); + assertEquals(envPath, list.getString("env1"), first.toJson()); + assertEquals(envPath, list.getString("env2"), first.toJson()); + } +} diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTest.java new file mode 100644 index 00000000000..3247dc28c06 --- /dev/null +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTest.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 static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +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.Test; + +@UsingMongoDb +@LoggerContextSource("log4j2-mongodb-auth-failure.xml") +public class MongoDbAuthFailureTest { + + @Test + public void test(final LoggerContext ctx, final MongoClient mongoClient) { + final Logger logger = ctx.getLogger(MongoDbAuthFailureTest.class); + logger.info("Hello log"); + final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME); + assertNotNull(database); + final MongoCollection collection = database.getCollection(MongoDbTestConstants.DATABASE_NAME); + assertNotNull(collection); + final Document first = collection.find().first(); + assertNull(first); + } +} diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedIntTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedIntTest.java new file mode 100644 index 00000000000..500964aff08 --- /dev/null +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedIntTest.java @@ -0,0 +1,26 @@ +/* + * 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.test.junit.LoggerContextSource; + +@UsingMongoDb +@LoggerContextSource("log4j2-mongodb-capped-int.xml") +public class MongoDbCappedIntTest extends AbstractMongoDbCappedTest { + + // test is in superclass +} diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedLongTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedLongTest.java new file mode 100644 index 00000000000..34f921fe7bf --- /dev/null +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedLongTest.java @@ -0,0 +1,26 @@ +/* + * 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.test.junit.LoggerContextSource; + +@UsingMongoDb +@LoggerContextSource("log4j2-mongodb-capped-long.xml") +public class MongoDbCappedLongTest extends AbstractMongoDbCappedTest { + + // test is in superclass +} diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTest.java new file mode 100644 index 00000000000..2733554dbd3 --- /dev/null +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTest.java @@ -0,0 +1,51 @@ +/* + * 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 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.apache.logging.log4j.message.MapMessage; +import org.bson.Document; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +@UsingMongoDb +@LoggerContextSource("log4j2-mongodb-map-message.xml") +public class MongoDbMapMessageTest { + + @Test + public void test(final LoggerContext ctx, final MongoClient mongoClient) { + final Logger logger = ctx.getLogger(MongoDbMapMessageTest.class); + final MapMessage mapMessage = new MapMessage<>(); + mapMessage.with("SomeName", "SomeValue"); + mapMessage.with("SomeInt", 1); + logger.info(mapMessage); + final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME); + Assertions.assertNotNull(database); + final MongoCollection collection = database.getCollection(MongoDbTestConstants.COLLECTION_NAME); + Assertions.assertNotNull(collection); + final Document first = collection.find().first(); + Assertions.assertNotNull(first); + final String firstJson = first.toJson(); + Assertions.assertEquals("SomeValue", first.getString("SomeName"), firstJson); + Assertions.assertEquals(Integer.valueOf(1), first.getInteger("SomeInt"), firstJson); + } +} diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java new file mode 100644 index 00000000000..68dc13f1ce1 --- /dev/null +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java @@ -0,0 +1,190 @@ +/* + * 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 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; +import de.flapdoodle.embed.mongo.transitions.Mongod; +import de.flapdoodle.embed.mongo.transitions.PackageOfCommandDistribution; +import de.flapdoodle.embed.mongo.transitions.RunningMongodProcess; +import de.flapdoodle.embed.mongo.types.DistributionBaseUrl; +import de.flapdoodle.embed.process.config.store.FileSet; +import de.flapdoodle.embed.process.config.store.FileType; +import de.flapdoodle.embed.process.config.store.Package; +import de.flapdoodle.embed.process.distribution.Distribution; +import de.flapdoodle.embed.process.io.ProcessOutput; +import de.flapdoodle.embed.process.io.Processors; +import de.flapdoodle.embed.process.io.StreamProcessor; +import de.flapdoodle.embed.process.types.Name; +import de.flapdoodle.embed.process.types.ProcessConfig; +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; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.status.StatusLogger; +import org.apache.logging.log4j.test.TestProperties; +import org.apache.logging.log4j.test.junit.ExtensionContextAnchor; +import org.apache.logging.log4j.test.junit.TestPropertySource; +import org.apache.logging.log4j.test.junit.TypeBasedParameterResolver; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +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 MongoDbResolver extends TypeBasedParameterResolver implements BeforeAllCallback { + + private static final Logger LOGGER = StatusLogger.getLogger(); + private static final String LOGGING_TARGET_PROPERTY = "log4j2.mongoDbLoggingTarget"; + + private static final int BUILDER_TIMEOUT_MILLIS = 30000; + + private static ProcessOutput getProcessOutput(final LoggingTarget loggingTarget, final String label) { + if (loggingTarget != null) { + switch (loggingTarget) { + case STATUS_LOGGER: + return ProcessOutput.builder() + .output(Processors.named( + "[" + label + " output]", new StatusLoggerStreamProcessor(Level.INFO))) + .error(Processors.named( + "[" + label + " error]", new StatusLoggerStreamProcessor(Level.ERROR))) + .commands(new StatusLoggerStreamProcessor(Level.DEBUG)) + .build(); + case CONSOLE: + return ProcessOutput.namedConsole(label); + default: + } + } + throw new NotImplementedException(Objects.toString(loggingTarget)); + } + + public MongoDbResolver() { + super(MongoClient.class); + } + + @Override + public void beforeAll(ExtensionContext context) throws Exception { + final TestProperties props = TestPropertySource.createProperties(context); + final Mongod mongod = Mongod.builder() + .processOutput(Derive.given(Name.class) + .state(ProcessOutput.class) + .deriveBy(name -> getProcessOutput( + LoggingTarget.getLoggingTarget(LoggingTarget.STATUS_LOGGER), name.value()))) + .processConfig(Start.to(ProcessConfig.class) + .initializedWith(ProcessConfig.defaults().withStopTimeoutInMillis(BUILDER_TIMEOUT_MILLIS)) + .withTransitionLabel("create default")) + // workaround for https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/issues/309 + .packageOfDistribution(new PackageOfCommandDistribution() { + + @Override + protected Package packageOf( + Command command, Distribution distribution, DistributionBaseUrl baseUrl) { + if (distribution.platform().operatingSystem().type() == OSType.Windows) { + final Package relativePackage = legacyPackageResolverFactory() + .apply(command) + .packageFor(distribution); + final FileSet.Builder fileSetBuilder = FileSet.builder() + .addEntry(FileType.Library, "ssleay32.dll") + .addEntry(FileType.Library, "libeay32.dll"); + relativePackage.fileSet().entries().forEach(fileSetBuilder::addEntries); + return Package.builder() + .archiveType(relativePackage.archiveType()) + .fileSet(fileSetBuilder.build()) + .url(baseUrl.value() + relativePackage.url()) + .hint(relativePackage.hint()) + .build(); + } + return super.packageOf(command, distribution, baseUrl); + } + }) + .build(); + ExtensionContextAnchor.setAttribute(MongoClientHolder.class, new MongoClientHolder(mongod, props), context); + } + + @Override + public MongoClient resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) + throws ParameterResolutionException { + return ExtensionContextAnchor.getAttribute(MongoClientHolder.class, MongoClientHolder.class, extensionContext) + .get(); + } + + public enum LoggingTarget { + CONSOLE, + STATUS_LOGGER; + + public static LoggingTarget getLoggingTarget(final LoggingTarget defaultValue) { + return LoggingTarget.valueOf(System.getProperty(LOGGING_TARGET_PROPERTY, defaultValue.name())); + } + } + + private static final class MongoClientHolder implements CloseableResource, Supplier { + private final ReachedState state; + private final MongoClient mongoClient; + + public MongoClientHolder(final Mongod mongod, final TestProperties props) { + state = mongod.start(Version.Main.V4_4); + final RunningMongodProcess mongodProcess = state.current(); + final ServerAddress addr = mongodProcess.getServerAddress(); + mongoClient = MongoClients.create(String.format("mongodb://%s:%d", addr.getHost(), addr.getPort())); + props.setProperty(MongoDbTestConstants.PROP_NAME_PORT, addr.getPort()); + } + + @Override + public MongoClient get() { + return mongoClient; + } + + @Override + public void close() throws Exception { + mongoClient.close(); + state.close(); + } + } + + private static final class StatusLoggerStreamProcessor implements StreamProcessor { + + private final Level level; + + public StatusLoggerStreamProcessor(Level level) { + this.level = level; + } + + @Override + public void process(String line) { + LOGGER.log(level, () -> stripLineEndings(line)); + } + + @Override + public void onProcessed() { + // noop + } + + 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-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolverTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolverTest.java new file mode 100644 index 00000000000..199cabcb2fe --- /dev/null +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolverTest.java @@ -0,0 +1,40 @@ +/* + * 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 static org.junit.jupiter.api.Assertions.assertNotNull; + +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoIterable; +import org.junit.jupiter.api.Test; + +/** + * Tests MongoDbRule. + *

+ * The test framework {@code de.flapdoodle.embed.mongo} requires Java 8. + *

+ */ +@UsingMongoDb +public class MongoDbResolverTest { + + @Test + public void testAccess(final MongoClient mongoClient) { + final MongoIterable databaseNames = mongoClient.listDatabaseNames(); + assertNotNull(databaseNames); + assertNotNull(databaseNames.first()); + } +} diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTest.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTest.java new file mode 100644 index 00000000000..5c4bbb750c1 --- /dev/null +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTest.java @@ -0,0 +1,59 @@ +/* + * 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 static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +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; +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.Test; + +@UsingMongoDb +@LoggerContextSource("log4j2-mongodb.xml") +public class MongoDbTest { + + @Test + public void test(final LoggerContext ctx, final MongoClient mongoClient) { + 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(MongoDbTestConstants.DATABASE_NAME); + assertNotNull(database); + final MongoCollection collection = database.getCollection(MongoDbTestConstants.COLLECTION_NAME); + assertNotNull(collection); + final FindIterable found = collection.find(); + final Document first = found.first(); + assertNotNull(first, "first"); + assertEquals("Hello log 1", first.getString("message"), first.toJson()); + assertEquals("INFO", first.getString("level"), first.toJson()); + // + found.skip(1); + final Document second = found.first(); + assertNotNull(second); + assertEquals("Hello log 2", second.getString("message"), second.toJson()); + assertEquals("INFO", second.getString("level"), second.toJson()); + final Document thrown = second.get("thrown", Document.class); + assertEquals("Hello ex 2", thrown.getString("message"), thrown.toJson()); + } +} diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestConstants.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestConstants.java new file mode 100644 index 00000000000..ed5435599b9 --- /dev/null +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestConstants.java @@ -0,0 +1,24 @@ +/* + * 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; + +public class MongoDbTestConstants { + + public static final String PROP_NAME_PORT = "MongoDBTestPort"; + static final String COLLECTION_NAME = "testCollection"; + static final String DATABASE_NAME = "testDb"; +} diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/UsingMongoDb.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/UsingMongoDb.java new file mode 100644 index 00000000000..8ad70c0d203 --- /dev/null +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/UsingMongoDb.java @@ -0,0 +1,36 @@ +/* + * 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 static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import org.apache.logging.log4j.test.junit.ExtensionContextAnchor; +import org.junit.jupiter.api.extension.ExtendWith; + +@Retention(RUNTIME) +@Target({TYPE, METHOD}) +@Inherited +@Documented +@ExtendWith(ExtensionContextAnchor.class) +@ExtendWith(MongoDbResolver.class) +public @interface UsingMongoDb {} diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb-additional-fields.xml b/log4j-mongodb/src/test/resources/log4j2-mongodb-additional-fields.xml new file mode 100644 index 00000000000..d9d27461a00 --- /dev/null +++ b/log4j-mongodb/src/test/resources/log4j2-mongodb-additional-fields.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb-auth-failure.xml b/log4j-mongodb/src/test/resources/log4j2-mongodb-auth-failure.xml new file mode 100644 index 00000000000..e84603a0a52 --- /dev/null +++ b/log4j-mongodb/src/test/resources/log4j2-mongodb-auth-failure.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb-capped-int.xml b/log4j-mongodb/src/test/resources/log4j2-mongodb-capped-int.xml new file mode 100644 index 00000000000..746b19914e7 --- /dev/null +++ b/log4j-mongodb/src/test/resources/log4j2-mongodb-capped-int.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb-capped-long.xml b/log4j-mongodb/src/test/resources/log4j2-mongodb-capped-long.xml new file mode 100644 index 00000000000..941ea71c4e2 --- /dev/null +++ b/log4j-mongodb/src/test/resources/log4j2-mongodb-capped-long.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb-map-message.xml b/log4j-mongodb/src/test/resources/log4j2-mongodb-map-message.xml new file mode 100644 index 00000000000..4b740bc947e --- /dev/null +++ b/log4j-mongodb/src/test/resources/log4j2-mongodb-map-message.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb.xml b/log4j-mongodb/src/test/resources/log4j2-mongodb.xml new file mode 100644 index 00000000000..4f0865b2c46 --- /dev/null +++ b/log4j-mongodb/src/test/resources/log4j2-mongodb.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 5d5459ee91a..def004d1a60 100644 --- a/pom.xml +++ b/pom.xml @@ -259,6 +259,7 @@ log4j-layout-template-json-test log4j-mongodb3 log4j-mongodb4 + log4j-mongodb log4j-osgi-test log4j-perf-test log4j-slf4j-impl 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 00000000000..7a3ee24b417 --- /dev/null +++ b/src/changelog/.2.x.x/add_log4j_mongodb.xml @@ -0,0 +1,8 @@ + + + + Add module log4j-mongodb to track the current MongoDB driver (currently version 5). + diff --git a/src/site/antora/modules/ROOT/pages/manual/appenders.adoc b/src/site/antora/modules/ROOT/pages/manual/appenders.adoc index 980dac7c529..8c79a8e422a 100644 --- a/src/site/antora/modules/ROOT/pages/manual/appenders.adoc +++ b/src/site/antora/modules/ROOT/pages/manual/appenders.adoc @@ -1927,12 +1927,100 @@ 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. +link:#NoSQLAppenderMongoDB4[`MongoDb4`] matching the MongoDB Driver version 4. +* Added in 2.24.0: `log4j-mongodb` defines the configuration element +link:#NoSQLAppenderMongoDB[`MongoDb`] matching the current MongoDB Driver (version 5). This module tracks the current MongoDB Driver. -We no longer provide the modules `log4j-mongodb`. +[#NoSQLAppenderMongoDB] +== NoSQLAppenderMongoDB for MongoDB + +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. + +.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]]`. + +|capped |boolean |Enable support for +https://docs.mongodb.com/manual/core/capped-collections/[capped +collections] + +|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 MongoDB4 +provider: -The module `log4j-mongodb2` aliases the old configuration element `MongoDb` to `MongoDb2`. +[source,xml] +---- + + + + + + + + + + + + + +---- + +[source,xml] +---- + + + + + + + + + + + + + +---- + +You can define additional fields to log using KeyValuePair elements, for example: + +[source,xml] +---- + + + + + + + + + + + + + + + + + +---- [[NoSQLAppenderMongoDB3]] == NoSQLAppender for MongoDB 3 @@ -2057,7 +2145,7 @@ You can define additional fields to log using `KeyValuePair` elements, for examp ---- [#NoSQLAppenderMongoDB4] -== NoSQLAppenderMongoDB4 +== NoSQLAppender for MongoDB 4 This section details specializations of the link:#NoSQLAppender[NoSQLAppender] provider for MongoDB using the From 72713ab326d6a666fc4c1f351c3329078fe1f80d Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 18 Apr 2024 09:59:54 -0400 Subject: [PATCH 2/9] Deprecate the log4j-mongodb4 module in favor of log4j-mongodb --- .../log4j/mongodb4/MongoDb4Provider.java | 5 ++++- src/changelog/.2.x.x/add_log4j_mongodb.xml | 1 - .../.2.x.x/deprecate_log4j_mongodb4.xml | 7 ++++++ .../modules/ROOT/pages/manual/appenders.adoc | 22 ++++++++++--------- .../modules/ROOT/pages/manual/messages.adoc | 2 +- 5 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 src/changelog/.2.x.x/deprecate_log4j_mongodb4.xml 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 171b4d296c7..2e8ead3d374 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 @@ * 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 { + private static final String PLUGIN_NAME = "MongoDb4"; + public static class Builder> extends AbstractFilterable.Builder implements org.apache.logging.log4j.core.util.Builder { @@ -55,6 +57,7 @@ public static class Builder> extends AbstractFilterable.Bui @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/src/changelog/.2.x.x/add_log4j_mongodb.xml b/src/changelog/.2.x.x/add_log4j_mongodb.xml index 7a3ee24b417..8227ff3d54b 100644 --- a/src/changelog/.2.x.x/add_log4j_mongodb.xml +++ b/src/changelog/.2.x.x/add_log4j_mongodb.xml @@ -3,6 +3,5 @@ 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"> - Add module log4j-mongodb to track the current MongoDB driver (currently version 5). 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 00000000000..e83cd2e7f14 --- /dev/null +++ b/src/changelog/.2.x.x/deprecate_log4j_mongodb4.xml @@ -0,0 +1,7 @@ + + + Deprecate the log4j-mongodb4 module in favor of log4j-mongodb. + diff --git a/src/site/antora/modules/ROOT/pages/manual/appenders.adoc b/src/site/antora/modules/ROOT/pages/manual/appenders.adoc index 8c79a8e422a..e4d60a2aded 100644 --- a/src/site/antora/modules/ROOT/pages/manual/appenders.adoc +++ b/src/site/antora/modules/ROOT/pages/manual/appenders.adoc @@ -1919,20 +1919,20 @@ 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 +* Added in 2.11.0, dropped in 2.14.0: `log4j-mongodb2` defines the configuration element MongoDb2 matching the MongoDB Driver version 2. +* Added in 2.11.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:#NoSQLAppenderMongoDB[`MongoDb`] matching the current MongoDB Driver (version 5). This module tracks the current MongoDB Driver. +link:#NoSQLAppenderMongoDBCurrent[`MongoDb`] matching the current MongoDB Driver (version 5). This module tracks the current MongoDB Driver. -[#NoSQLAppenderMongoDB] -== NoSQLAppenderMongoDB for MongoDB +[#NoSQLAppenderMongoDBCurrent] +== NoSQL Appender for MongoDB This section details specializations of the link:#NoSQLAppender[NoSQLAppender] provider for MongoDB using the @@ -2023,7 +2023,7 @@ You can define additional fields to log using KeyValuePair elements, for example ---- [[NoSQLAppenderMongoDB3]] -== NoSQLAppender for MongoDB 3 +== NoSQL Appender 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. @@ -2145,7 +2145,9 @@ You can define additional fields to log using `KeyValuePair` elements, for examp ---- [#NoSQLAppenderMongoDB4] -== NoSQLAppender for MongoDB 4 +== (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 7769192eb81..8f2128f4303 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. From ae8743e4661a06123a12c0714b5af3187b00c577 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 18 Apr 2024 10:12:16 -0400 Subject: [PATCH 3/9] Remove module log4j-mongodb3, use log4j-mongodb instead Note: log4j-mongodb4 is deprecated for removal --- .../.log4j-plugin-processing-activator | 1 - log4j-mongodb3/pom.xml | 170 --------- .../logging/log4j/mongodb3/LevelCodec.java | 52 --- .../log4j/mongodb3/MongoDbConnection.java | 102 ----- .../log4j/mongodb3/MongoDbDocumentObject.java | 61 --- .../mongodb3/MongoDbDocumentObjectCodec.java | 49 --- .../log4j/mongodb3/MongoDbProvider.java | 352 ------------------ .../logging/log4j/mongodb3/package-info.java | 27 -- .../MongoDb3AdditionalFieldsTest.java | 74 ---- .../mongodb3/MongoDb3AuthFailureTest.java | 46 --- .../log4j/mongodb3/MongoDb3CappedTest.java | 45 --- .../mongodb3/MongoDb3MapMessageTest.java | 51 --- .../log4j/mongodb3/MongoDb3Resolver.java | 184 --------- .../log4j/mongodb3/MongoDb3ResolverTest.java | 40 -- .../logging/log4j/mongodb3/MongoDb3Test.java | 59 --- .../log4j/mongodb3/MongoDb3TestConstants.java | 24 -- .../logging/log4j/mongodb3/UsingMongoDb3.java | 36 -- .../log4j2-mongodb-additional-fields.xml | 34 -- .../resources/log4j2-mongodb-auth-failure.xml | 30 -- .../test/resources/log4j2-mongodb-capped.xml | 30 -- .../resources/log4j2-mongodb-map-message.xml | 31 -- .../src/test/resources/log4j2-mongodb.xml | 30 -- pom.xml | 5 +- .../.2.x.x/remove_log4j_mongodb3.xml | 7 + .../modules/ROOT/pages/manual/appenders.adoc | 126 +------ 25 files changed, 11 insertions(+), 1655 deletions(-) delete mode 100644 log4j-mongodb3/.log4j-plugin-processing-activator delete mode 100644 log4j-mongodb3/pom.xml delete mode 100644 log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/LevelCodec.java delete mode 100644 log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbConnection.java delete mode 100644 log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbDocumentObject.java delete mode 100644 log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbDocumentObjectCodec.java delete mode 100644 log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/MongoDbProvider.java delete mode 100644 log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/package-info.java delete mode 100644 log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AdditionalFieldsTest.java delete mode 100644 log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AuthFailureTest.java delete mode 100644 log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3CappedTest.java delete mode 100644 log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3MapMessageTest.java delete mode 100644 log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3Resolver.java delete mode 100644 log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3ResolverTest.java delete mode 100644 log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3Test.java delete mode 100644 log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3TestConstants.java delete mode 100644 log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/UsingMongoDb3.java delete mode 100644 log4j-mongodb3/src/test/resources/log4j2-mongodb-additional-fields.xml delete mode 100644 log4j-mongodb3/src/test/resources/log4j2-mongodb-auth-failure.xml delete mode 100644 log4j-mongodb3/src/test/resources/log4j2-mongodb-capped.xml delete mode 100644 log4j-mongodb3/src/test/resources/log4j2-mongodb-map-message.xml delete mode 100644 log4j-mongodb3/src/test/resources/log4j2-mongodb.xml create mode 100644 src/changelog/.2.x.x/remove_log4j_mongodb3.xml diff --git a/log4j-mongodb3/.log4j-plugin-processing-activator b/log4j-mongodb3/.log4j-plugin-processing-activator deleted file mode 100644 index ba133f36961..00000000000 --- a/log4j-mongodb3/.log4j-plugin-processing-activator +++ /dev/null @@ -1 +0,0 @@ -This file is here to activate the `plugin-processing` Maven profile. diff --git a/log4j-mongodb3/pom.xml b/log4j-mongodb3/pom.xml deleted file mode 100644 index b1225582b2a..00000000000 --- a/log4j-mongodb3/pom.xml +++ /dev/null @@ -1,170 +0,0 @@ - - - - - 4.0.0 - - - org.apache.logging.log4j - log4j - ${revision} - ../log4j-parent - - - log4j-mongodb3 - - Apache Log4j MongoDB 3 - MongoDB appender for Log4j using the MongoDB 3 driver API. - - - - - - - mongodb.driver.legacy;substitute="mongodb-driver-legacy";static=true;transitive=false - - org.apache.logging.log4j.core - - - 3.12.14 - - - - - - org.mongodb - bson - ${mongodb3.version} - - - org.mongodb - mongodb-driver-core - ${mongodb3.version} - - - org.mongodb - mongodb-driver-legacy - ${mongodb3.version} - - - org.mongodb - mongodb-driver-sync - ${mongodb3.version} - - - - - - - org.apache.logging.log4j - log4j-api - - - org.apache.logging.log4j - log4j-core - - - org.mongodb - bson - - - org.mongodb - mongodb-driver-core - - - org.mongodb - mongodb-driver-legacy - - - org.mongodb - mongodb-driver-sync - - - org.apache.logging.log4j - log4j-api-test - test - - - junit - junit - - - - - org.apache.logging.log4j - log4j-core-test - test - - - junit - junit - - - - - org.apache.commons - commons-lang3 - test - - - de.flapdoodle.embed - de.flapdoodle.embed.mongo - test - - - de.flapdoodle.embed - de.flapdoodle.embed.process - test - - - de.flapdoodle.reverse - de.flapdoodle.reverse - test - - - org.junit.jupiter - junit-jupiter-api - test - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - 1 - - - - org.junit.jupiter - junit-jupiter-engine - ${junit-jupiter.version} - - - - - - - - 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 5e6826d4580..00000000000 --- 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 { - - /** - * 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 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 ac34650ee49..00000000000 --- 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 { - - private static final Logger LOGGER = StatusLogger.getLogger(); - - private static MongoCollection 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 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 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 31798bc2db6..00000000000 --- 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 { - - private final Document document; - - /** - * Constructs a new instance. - */ - public MongoDbDocumentObject() { - this.document = new Document(); - } - - @Override - public void set(final String field, final NoSqlObject value) { - this.document.append(field, value != null ? value.unwrap() : null); - } - - @Override - public void set(final String field, final NoSqlObject[] 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 812ca96ee38..00000000000 --- 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 { - - private final Codec 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 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 90a9a6f4928..00000000000 --- 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 { - - public static class Builder> extends AbstractFilterable.Builder - implements org.apache.logging.log4j.core.util.Builder { - - // @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 newBuilder() { - return new Builder().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-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/package-info.java b/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/package-info.java deleted file mode 100644 index 9a8fe2c1188..00000000000 --- a/log4j-mongodb3/src/main/java/org/apache/logging/log4j/mongodb3/package-info.java +++ /dev/null @@ -1,27 +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. - */ -/** - * 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; - -import aQute.bnd.annotation.jpms.Open; -import org.osgi.annotation.bundle.Export; -import org.osgi.annotation.versioning.Version; diff --git a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AdditionalFieldsTest.java b/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AdditionalFieldsTest.java deleted file mode 100644 index 3bb6f0b5f5f..00000000000 --- a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AdditionalFieldsTest.java +++ /dev/null @@ -1,74 +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 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.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.Test; - -@UsingMongoDb3 -@LoggerContextSource("log4j2-mongodb-additional-fields.xml") -public class MongoDb3AdditionalFieldsTest { - - @Test - public void test(final LoggerContext ctx, final MongoClient mongoClient) { - final Logger logger = ctx.getLogger(MongoDb3AdditionalFieldsTest.class); - logger.info("Hello log 1"); - logger.info("Hello log 2", new RuntimeException("Hello ex 2")); - final MongoDatabase database = mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME); - assertNotNull(database); - final MongoCollection collection = database.getCollection(MongoDb3TestConstants.COLLECTION_NAME); - assertNotNull(collection); - final FindIterable found = collection.find(); - final Document first = found.first(); - assertNotNull(first, "first"); - assertEquals("Hello log 1", first.getString("message"), first.toJson()); - assertEquals("INFO", first.getString("level"), first.toJson()); - // - Document list; - final String envPath = System.getenv("PATH"); - // - list = first.get("additionalFields", Document.class); - assertEquals("1", list.getString("A"), first.toJson()); - assertEquals("2", list.getString("B"), first.toJson()); - assertEquals(envPath, list.getString("env1"), first.toJson()); - assertEquals(envPath, list.getString("env2"), first.toJson()); - // - found.skip(1); - final Document second = found.first(); - assertNotNull(second); - assertEquals("Hello log 2", second.getString("message"), second.toJson()); - assertEquals("INFO", second.getString("level"), second.toJson()); - final Document thrown = second.get("thrown", Document.class); - assertEquals("Hello ex 2", thrown.getString("message"), thrown.toJson()); - // - list = second.get("additionalFields", Document.class); - assertEquals("1", list.getString("A"), first.toJson()); - assertEquals("2", list.getString("B"), first.toJson()); - assertEquals(envPath, list.getString("env1"), first.toJson()); - assertEquals(envPath, list.getString("env2"), first.toJson()); - } -} diff --git a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AuthFailureTest.java b/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AuthFailureTest.java deleted file mode 100644 index 847d5c03ff5..00000000000 --- a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3AuthFailureTest.java +++ /dev/null @@ -1,46 +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 static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -import com.mongodb.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.Test; - -@UsingMongoDb3 -@LoggerContextSource("log4j2-mongodb-auth-failure.xml") -public class MongoDb3AuthFailureTest { - - @Test - public void test(final LoggerContext ctx, final MongoClient mongoClient) { - final Logger logger = ctx.getLogger(MongoDb3AuthFailureTest.class); - logger.info("Hello log"); - final MongoDatabase database = mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME); - assertNotNull(database); - final MongoCollection collection = database.getCollection(MongoDb3TestConstants.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/MongoDb3CappedTest.java b/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3CappedTest.java deleted file mode 100644 index 71ad196192a..00000000000 --- a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3CappedTest.java +++ /dev/null @@ -1,45 +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.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 { - - @Test - public void test(final LoggerContext ctx, final MongoClient mongoClient) { - final Logger logger = ctx.getLogger(MongoDb3CappedTest.class); - logger.info("Hello log"); - final MongoDatabase database = mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME); - Assertions.assertNotNull(database); - final MongoCollection collection = database.getCollection(MongoDb3TestConstants.COLLECTION_NAME); - Assertions.assertNotNull(collection); - final Document first = collection.find().first(); - Assertions.assertNotNull(first); - Assertions.assertEquals("Hello log", first.getString("message"), first.toJson()); - } -} diff --git a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3MapMessageTest.java b/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3MapMessageTest.java deleted file mode 100644 index cada31f18bc..00000000000 --- a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3MapMessageTest.java +++ /dev/null @@ -1,51 +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.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.apache.logging.log4j.message.MapMessage; -import org.bson.Document; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -@UsingMongoDb3 -@LoggerContextSource("log4j2-mongodb-map-message.xml") -public class MongoDb3MapMessageTest { - - @Test - public void test(final LoggerContext ctx, final MongoClient mongoClient) { - final Logger logger = ctx.getLogger(MongoDb3MapMessageTest.class); - final MapMessage mapMessage = new MapMessage<>(); - mapMessage.with("SomeName", "SomeValue"); - mapMessage.with("SomeInt", 1); - logger.info(mapMessage); - final MongoDatabase database = mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME); - Assertions.assertNotNull(database); - final MongoCollection collection = database.getCollection(MongoDb3TestConstants.COLLECTION_NAME); - Assertions.assertNotNull(collection); - final Document first = collection.find().first(); - Assertions.assertNotNull(first); - final String firstJson = first.toJson(); - Assertions.assertEquals("SomeValue", first.getString("SomeName"), firstJson); - Assertions.assertEquals(Integer.valueOf(1), first.getInteger("SomeInt"), firstJson); - } -} diff --git a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3Resolver.java b/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3Resolver.java deleted file mode 100644 index 5df14b9abc4..00000000000 --- a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3Resolver.java +++ /dev/null @@ -1,184 +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 de.flapdoodle.embed.mongo.commands.ServerAddress; -import de.flapdoodle.embed.mongo.distribution.Version; -import de.flapdoodle.embed.mongo.packageresolver.Command; -import de.flapdoodle.embed.mongo.transitions.Mongod; -import de.flapdoodle.embed.mongo.transitions.PackageOfCommandDistribution; -import de.flapdoodle.embed.mongo.transitions.RunningMongodProcess; -import de.flapdoodle.embed.mongo.types.DistributionBaseUrl; -import de.flapdoodle.embed.process.config.store.FileSet; -import de.flapdoodle.embed.process.config.store.FileType; -import de.flapdoodle.embed.process.config.store.Package; -import de.flapdoodle.embed.process.distribution.Distribution; -import de.flapdoodle.embed.process.io.ProcessOutput; -import de.flapdoodle.embed.process.io.Processors; -import de.flapdoodle.embed.process.io.StreamProcessor; -import de.flapdoodle.embed.process.types.Name; -import de.flapdoodle.embed.process.types.ProcessConfig; -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.function.Supplier; -import org.apache.commons.lang3.NotImplementedException; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.status.StatusLogger; -import org.apache.logging.log4j.test.TestProperties; -import org.apache.logging.log4j.test.junit.ExtensionContextAnchor; -import org.apache.logging.log4j.test.junit.TestPropertySource; -import org.apache.logging.log4j.test.junit.TypeBasedParameterResolver; -import org.junit.jupiter.api.extension.BeforeAllCallback; -import org.junit.jupiter.api.extension.ExtensionContext; -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 implements BeforeAllCallback { - - private static final Logger LOGGER = StatusLogger.getLogger(); - private static final String LOGGING_TARGET_PROPERTY = "log4j2.mongoDbLoggingTarget"; - - private static final int BUILDER_TIMEOUT_MILLIS = 30000; - - private static ProcessOutput getProcessOutput(final LoggingTarget loggingTarget, final String label) { - if (loggingTarget != null) { - switch (loggingTarget) { - case STATUS_LOGGER: - return ProcessOutput.builder() - .output(Processors.named( - "[" + label + " output]", new StatusLoggerStreamProcessor(Level.INFO))) - .error(Processors.named( - "[" + label + " error]", new StatusLoggerStreamProcessor(Level.ERROR))) - .commands(new StatusLoggerStreamProcessor(Level.DEBUG)) - .build(); - case CONSOLE: - return ProcessOutput.namedConsole(label); - default: - } - } - throw new NotImplementedException(loggingTarget.toString()); - } - - public MongoDb3Resolver() { - super(MongoClient.class); - } - - @Override - public void beforeAll(ExtensionContext context) throws Exception { - final TestProperties props = TestPropertySource.createProperties(context); - final Mongod mongod = Mongod.builder() - .processOutput(Derive.given(Name.class) - .state(ProcessOutput.class) - .deriveBy(name -> getProcessOutput( - LoggingTarget.getLoggingTarget(LoggingTarget.STATUS_LOGGER), name.value()))) - .processConfig(Start.to(ProcessConfig.class) - .initializedWith(ProcessConfig.defaults().withStopTimeoutInMillis(BUILDER_TIMEOUT_MILLIS)) - .withTransitionLabel("create default")) - // workaround for https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/issues/309 - .packageOfDistribution(new PackageOfCommandDistribution() { - - @Override - protected Package packageOf( - Command command, Distribution distribution, DistributionBaseUrl baseUrl) { - if (distribution.platform().operatingSystem().type() == OSType.Windows) { - final Package relativePackage = legacyPackageResolverFactory() - .apply(command) - .packageFor(distribution); - final FileSet.Builder fileSetBuilder = FileSet.builder() - .addEntry(FileType.Library, "ssleay32.dll") - .addEntry(FileType.Library, "libeay32.dll"); - relativePackage.fileSet().entries().forEach(fileSetBuilder::addEntries); - return Package.builder() - .archiveType(relativePackage.archiveType()) - .fileSet(fileSetBuilder.build()) - .url(baseUrl.value() + relativePackage.url()) - .hint(relativePackage.hint()) - .build(); - } - return super.packageOf(command, distribution, baseUrl); - } - }) - .build(); - ExtensionContextAnchor.setAttribute(MongoClientHolder.class, new MongoClientHolder(mongod, props), context); - } - - @Override - public MongoClient resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) - throws ParameterResolutionException { - return ExtensionContextAnchor.getAttribute(MongoClientHolder.class, MongoClientHolder.class, extensionContext) - .get(); - } - - public enum LoggingTarget { - CONSOLE, - STATUS_LOGGER; - - public static LoggingTarget getLoggingTarget(final LoggingTarget defaultValue) { - return LoggingTarget.valueOf(System.getProperty(LOGGING_TARGET_PROPERTY, defaultValue.name())); - } - } - - private static final class MongoClientHolder implements CloseableResource, Supplier { - private final ReachedState state; - private final MongoClient mongoClient; - - public MongoClientHolder(final Mongod mongod, final TestProperties props) { - state = mongod.start(Version.Main.V3_6); - 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()); - } - - @Override - public MongoClient get() { - return mongoClient; - } - - @Override - public void close() throws Exception { - mongoClient.close(); - state.close(); - } - } - - private static final class StatusLoggerStreamProcessor implements StreamProcessor { - - private final Level level; - - public StatusLoggerStreamProcessor(Level level) { - this.level = level; - } - - public void process(String line) { - LOGGER.log(level, () -> stripLineEndings(line)); - } - - public void onProcessed() {} - - protected 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-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3ResolverTest.java deleted file mode 100644 index 46c7b2eb16a..00000000000 --- a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3ResolverTest.java +++ /dev/null @@ -1,40 +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 static org.junit.jupiter.api.Assertions.assertNotNull; - -import com.mongodb.MongoClient; -import com.mongodb.client.MongoIterable; -import org.junit.jupiter.api.Test; - -/** - * Tests MongoDbRule. - *

- * The test framework {@code de.flapdoodle.embed.mongo} requires Java 8. - *

- */ -@UsingMongoDb3 -public class MongoDb3ResolverTest { - - @Test - public void testAccess(final MongoClient mongoClient) { - final MongoIterable databaseNames = mongoClient.listDatabaseNames(); - assertNotNull(databaseNames); - assertNotNull(databaseNames.first()); - } -} diff --git a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3Test.java b/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3Test.java deleted file mode 100644 index 449c0819bf7..00000000000 --- a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3Test.java +++ /dev/null @@ -1,59 +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 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.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.Test; - -@UsingMongoDb3 -@LoggerContextSource("log4j2-mongodb.xml") -public class MongoDb3Test { - - @Test - public void test(final LoggerContext ctx, final MongoClient mongoClient) { - final Logger logger = ctx.getLogger(MongoDb3Test.class); - logger.info("Hello log 1"); - logger.info("Hello log 2", new RuntimeException("Hello ex 2")); - final MongoDatabase database = mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME); - assertNotNull(database); - final MongoCollection collection = database.getCollection(MongoDb3TestConstants.COLLECTION_NAME); - assertNotNull(collection); - final FindIterable found = collection.find(); - final Document first = found.first(); - assertNotNull(first, "first"); - assertEquals("Hello log 1", first.getString("message"), first.toJson()); - assertEquals("INFO", first.getString("level"), first.toJson()); - // - found.skip(1); - final Document second = found.first(); - assertNotNull(second); - assertEquals("Hello log 2", second.getString("message"), second.toJson()); - assertEquals("INFO", second.getString("level"), second.toJson()); - final Document thrown = second.get("thrown", Document.class); - assertEquals("Hello ex 2", thrown.getString("message"), thrown.toJson()); - } -} diff --git a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3TestConstants.java b/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3TestConstants.java deleted file mode 100644 index 1b06fce9f3d..00000000000 --- a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/MongoDb3TestConstants.java +++ /dev/null @@ -1,24 +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; - -public class MongoDb3TestConstants { - - public static final String PROP_NAME_PORT = "MongoDBTestPort"; - static final String COLLECTION_NAME = "testCollection"; - static final String DATABASE_NAME = "testDb"; -} diff --git a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/UsingMongoDb3.java b/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/UsingMongoDb3.java deleted file mode 100644 index 47a5c89f18c..00000000000 --- a/log4j-mongodb3/src/test/java/org/apache/logging/log4j/mongodb3/UsingMongoDb3.java +++ /dev/null @@ -1,36 +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 static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Documented; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; -import org.apache.logging.log4j.test.junit.ExtensionContextAnchor; -import org.junit.jupiter.api.extension.ExtendWith; - -@Retention(RUNTIME) -@Target({TYPE, METHOD}) -@Inherited -@Documented -@ExtendWith(ExtensionContextAnchor.class) -@ExtendWith(MongoDb3Resolver.class) -public @interface UsingMongoDb3 {} diff --git a/log4j-mongodb3/src/test/resources/log4j2-mongodb-additional-fields.xml b/log4j-mongodb3/src/test/resources/log4j2-mongodb-additional-fields.xml deleted file mode 100644 index e75b9b6f8ee..00000000000 --- a/log4j-mongodb3/src/test/resources/log4j2-mongodb-additional-fields.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/log4j-mongodb3/src/test/resources/log4j2-mongodb-auth-failure.xml b/log4j-mongodb3/src/test/resources/log4j2-mongodb-auth-failure.xml deleted file mode 100644 index 434c70ceea6..00000000000 --- a/log4j-mongodb3/src/test/resources/log4j2-mongodb-auth-failure.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - diff --git a/log4j-mongodb3/src/test/resources/log4j2-mongodb-capped.xml b/log4j-mongodb3/src/test/resources/log4j2-mongodb-capped.xml deleted file mode 100644 index b147e8cd5fd..00000000000 --- a/log4j-mongodb3/src/test/resources/log4j2-mongodb-capped.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - diff --git a/log4j-mongodb3/src/test/resources/log4j2-mongodb-map-message.xml b/log4j-mongodb3/src/test/resources/log4j2-mongodb-map-message.xml deleted file mode 100644 index 16fd4a5d4de..00000000000 --- a/log4j-mongodb3/src/test/resources/log4j2-mongodb-map-message.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/log4j-mongodb3/src/test/resources/log4j2-mongodb.xml b/log4j-mongodb3/src/test/resources/log4j2-mongodb.xml deleted file mode 100644 index d00d48124a4..00000000000 --- a/log4j-mongodb3/src/test/resources/log4j2-mongodb.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index def004d1a60..47a383e3639 100644 --- a/pom.xml +++ b/pom.xml @@ -257,7 +257,6 @@ log4j-jul log4j-layout-template-json log4j-layout-template-json-test - log4j-mongodb3 log4j-mongodb4 log4j-mongodb log4j-osgi-test @@ -474,13 +473,13 @@ org.apache.logging.log4j - log4j-mongodb3 + log4j-mongodb4 ${project.version} org.apache.logging.log4j - log4j-mongodb4 + log4j-mongodb ${project.version} 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 00000000000..310e97f51be --- /dev/null +++ b/src/changelog/.2.x.x/remove_log4j_mongodb3.xml @@ -0,0 +1,7 @@ + + + Remove module log4j-mongodb3, use log4j-mongodb instead, log4j-mongodb4 is deprecated for removal. + diff --git a/src/site/antora/modules/ROOT/pages/manual/appenders.adoc b/src/site/antora/modules/ROOT/pages/manual/appenders.adoc index e4d60a2aded..f473f73483e 100644 --- a/src/site/antora/modules/ROOT/pages/manual/appenders.adoc +++ b/src/site/antora/modules/ROOT/pages/manual/appenders.adoc @@ -1924,8 +1924,8 @@ databases if represented in a JSON format: Starting with Log4 2.11.0, we provide the following MongoDB modules: -* Added in 2.11.0, dropped in 2.14.0: `log4j-mongodb2` defines the configuration element MongoDb2 matching the MongoDB Driver version 2. -* Added in 2.11.0: `log4j-mongodb3` defines the configuration element MongoDb3 matching the MongoDB Driver version 3. +* 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 @@ -2022,128 +2022,6 @@ You can define additional fields to log using KeyValuePair elements, for example ---- -[[NoSQLAppenderMongoDB3]] -== NoSQL Appender 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. - -[width="100%",options="header"] -|=== -|Parameter Name |Type |Description - -|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` attributes. - -|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]. - -|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. -|=== - -This appender is xref:manual/messages.adoc#MapMessage[MapMessage]-aware. - -Here are a few sample configurations for the NoSQLAppender and MongoDB3 provider: - -[source,xml] ----- - - - - - - - - - - - - - ----- - -[source,xml] ----- - - - - - - - - - - - - - ----- - -You can define additional fields to log using `KeyValuePair` elements, for example: - -[source,xml] ----- - - - - - - - - - - - - - - - - - ----- - [#NoSQLAppenderMongoDB4] == (Deprecated) No SQLAppender for MongoDB 4 From 47ad9f1b00c5cfbbf924532884904ef02e5a9258 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 18 Apr 2024 10:33:06 -0400 Subject: [PATCH 4/9] Deprecate the log4j-mongodb4 module in favor of log4j-mongodb --- .../org/apache/logging/log4j/mongodb4/MongoDb4Provider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2e8ead3d374..299e369630b 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 @@ -40,7 +40,7 @@ @Plugin(name = MongoDb4Provider.PLUGIN_NAME, category = Core.CATEGORY_NAME, printObject = true) public final class MongoDb4Provider implements NoSqlProvider { - private static final String PLUGIN_NAME = "MongoDb4"; + static final String PLUGIN_NAME = "MongoDb4"; public static class Builder> extends AbstractFilterable.Builder implements org.apache.logging.log4j.core.util.Builder { From c86b1564503f31aeba4a03aaa247579f6b50ad19 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 19 Apr 2024 10:23:10 -0400 Subject: [PATCH 5/9] Bump MongoDB version to test from 4.4 to 7.0.8 Co-authored-by: Piotr P. Karwasz --- .../java/org/apache/logging/log4j/mongodb/MongoDbResolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java index 68dc13f1ce1..ab2674a986b 100644 --- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java @@ -144,7 +144,7 @@ private static final class MongoClientHolder implements CloseableResource, Suppl 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_8); final RunningMongodProcess mongodProcess = state.current(); final ServerAddress addr = mongodProcess.getServerAddress(); mongoClient = MongoClients.create(String.format("mongodb://%s:%d", addr.getHost(), addr.getPort())); From c0de361a0346be70391e3ebb0a9e52c779156764 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 19 Apr 2024 10:25:42 -0400 Subject: [PATCH 6/9] Update package-info.java --- .../java/org/apache/logging/log4j/mongodb/package-info.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/package-info.java b/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/package-info.java index 7e8d5c80531..3ff159c9e54 100644 --- a/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/package-info.java +++ b/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/package-info.java @@ -20,7 +20,7 @@ */ @Export @Open("org.apache.logging.log4j.core") -@Version("2.21.0") +@Version("2.24.0") package org.apache.logging.log4j.mongodb; import aQute.bnd.annotation.jpms.Open; From 4e1cfe6d8e4cf7d736dd7d65232b1a8916f97857 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 19 Apr 2024 11:30:49 -0400 Subject: [PATCH 7/9] Fix compilation --- .../java/org/apache/logging/log4j/mongodb/MongoDbResolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java index ab2674a986b..68dc13f1ce1 100644 --- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java @@ -144,7 +144,7 @@ private static final class MongoClientHolder implements CloseableResource, Suppl private final MongoClient mongoClient; public MongoClientHolder(final Mongod mongod, final TestProperties props) { - state = mongod.start(Version.Main.V7_0_8); + state = mongod.start(Version.Main.V4_4); final RunningMongodProcess mongodProcess = state.current(); final ServerAddress addr = mongodProcess.getServerAddress(); mongoClient = MongoClients.create(String.format("mongodb://%s:%d", addr.getHost(), addr.getPort())); From 8f7e0443bcd13302d58bb4aa6415d7dbcb3f0d80 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 19 Apr 2024 16:25:22 -0400 Subject: [PATCH 8/9] Bump tests from MongoDB Server 4.4 to 7.0 --- .../java/org/apache/logging/log4j/mongodb/MongoDbResolver.java | 2 +- .../org/apache/logging/log4j/mongodb4/MongoDb4Resolver.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java index 68dc13f1ce1..e478ba9bbdd 100644 --- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbResolver.java @@ -144,7 +144,7 @@ private static final class MongoClientHolder implements CloseableResource, Suppl 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/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 fe4a4c18a29..da937eb3ec9 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 @@ private static final class MongoClientHolder implements CloseableResource, Suppl 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())); From 904083bcdd2dc1214017a021d21763aea40ea663 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 19 Apr 2024 16:26:53 -0400 Subject: [PATCH 9/9] Use AB order in modules --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 47a383e3639..a1883a55dca 100644 --- a/pom.xml +++ b/pom.xml @@ -257,8 +257,8 @@ log4j-jul log4j-layout-template-json log4j-layout-template-json-test - log4j-mongodb4 log4j-mongodb + log4j-mongodb4 log4j-osgi-test log4j-perf-test log4j-slf4j-impl