Skip to content

Feature/2.x/mongodb next gg #2486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 13 additions & 33 deletions log4j-mongodb3/pom.xml → log4j-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,69 +16,57 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>
<version>${revision}</version>
<relativePath>../log4j-parent</relativePath>
</parent>

<artifactId>log4j-mongodb3</artifactId>

<name>Apache Log4j MongoDB 3</name>
<description>MongoDB appender for Log4j using the MongoDB 3 driver API.</description>

<artifactId>log4j-mongodb</artifactId>
<name>Apache Log4j MongoDB Appender</name>
<description>MongoDB appender for Log4j using the MongoDB 5 driver API.</description>
<properties>

<!--
~ OSGi and JPMS options
-->
<bnd-extra-module-options>
<!-- Filebased module names: MUST be static -->
mongodb.driver.legacy;substitute="mongodb-driver-legacy";static=true;transitive=false
</bnd-extra-module-options>
<!-- OSGi and JPMS options -->
<Fragment-Host>org.apache.logging.log4j.core</Fragment-Host>

<!-- Dependency versions -->
<mongodb3.version>3.12.14</mongodb3.version>
<mongodb5.version>5.0.1</mongodb5.version>
<!-- TODO: Remove in next release after 2.24.0. -->
<bnd.baseline.fail.on.missing>false</bnd.baseline.fail.on.missing>
<bnd.baseline.skip>true</bnd.baseline.skip>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>${mongodb3.version}</version>
<version>${mongodb5.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
<version>${mongodb3.version}</version>
<version>${mongodb5.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-legacy</artifactId>
<version>${mongodb3.version}</version>
<version>${mongodb5.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>${mongodb3.version}</version>
<version>${mongodb5.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<artifactId>log4j-mongodb4</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
Expand All @@ -88,10 +76,6 @@
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-legacy</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
Expand Down Expand Up @@ -144,10 +128,8 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand All @@ -163,8 +145,6 @@
</dependency>
</dependencies>
</plugin>

</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.logging.log4j.mongodb;

import org.apache.logging.log4j.core.Core;
import org.apache.logging.log4j.core.appender.nosql.NoSqlProvider;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
import org.apache.logging.log4j.mongodb4.MongoDb4Connection;
import org.apache.logging.log4j.mongodb4.MongoDb4Provider;
import org.apache.logging.log4j.mongodb4.MongoDb4Provider.Builder;

/**
* Delegates to {@link MongoDb4Provider} under the name {@code MongoDb}.
*/
/*
* TODO: Currently the
* {@link org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor}
* assumes that the class generated by the plugin is the same as the annotated class.
* To work around this we declare this class abstract and let it implement
* {@link NoSqlProvider}.
*/
@Plugin(name = "MongoDb", category = Core.CATEGORY_NAME, printObject = true)
public abstract class MongoDbProvider implements NoSqlProvider<MongoDb4Connection> {

private MongoDbProvider() {}

@PluginBuilderFactory
public static <B extends Builder<B>> B newBuilder() {
return MongoDb4Provider.newBuilder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
* limitations under the license.
*/
/**
* The classes in this package contain the MongoDB provider for the NoSQL Appender.
* The classes in this package contain the MongoDB provider for the NoSQL
* Appender.
*/
@Export
@Open("org.apache.logging.log4j.core")
@Version("2.20.1")
package org.apache.logging.log4j.mongodb3;
@Version("2.24.0")
package org.apache.logging.log4j.mongodb;

import aQute.bnd.annotation.jpms.Open;
import org.osgi.annotation.bundle.Export;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.logging.log4j.mongodb3;
package org.apache.logging.log4j.mongodb;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.bson.Document;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

@UsingMongoDb3
@LoggerContextSource("log4j2-mongodb-capped.xml")
public class MongoDb3CappedTest {
public abstract class AbstractMongoDbCappedTest {

@Test
public void test(final LoggerContext ctx, final MongoClient mongoClient) {
final Logger logger = ctx.getLogger(MongoDb3CappedTest.class);
final Logger logger = ctx.getLogger(AbstractMongoDbCappedTest.class);
logger.info("Hello log");
final MongoDatabase database = mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME);
final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
Assertions.assertNotNull(database);
final MongoCollection<Document> collection = database.getCollection(MongoDb3TestConstants.COLLECTION_NAME);
final MongoCollection<Document> collection = database.getCollection(MongoDbTestConstants.COLLECTION_NAME);
Assertions.assertNotNull(collection);
final Document first = collection.find().first();
Assertions.assertNotNull(first);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.logging.log4j.mongodb3;
package org.apache.logging.log4j.mongodb;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import com.mongodb.MongoClient;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.apache.logging.log4j.Logger;
Expand All @@ -29,18 +29,18 @@
import org.bson.Document;
import org.junit.jupiter.api.Test;

@UsingMongoDb3
@UsingMongoDb
@LoggerContextSource("log4j2-mongodb-additional-fields.xml")
public class MongoDb3AdditionalFieldsTest {
public class MongoDbAdditionalFieldsTest {

@Test
public void test(final LoggerContext ctx, final MongoClient mongoClient) {
final Logger logger = ctx.getLogger(MongoDb3AdditionalFieldsTest.class);
final Logger logger = ctx.getLogger(MongoDbAdditionalFieldsTest.class);
logger.info("Hello log 1");
logger.info("Hello log 2", new RuntimeException("Hello ex 2"));
final MongoDatabase database = mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME);
final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
assertNotNull(database);
final MongoCollection<Document> collection = database.getCollection(MongoDb3TestConstants.COLLECTION_NAME);
final MongoCollection<Document> collection = database.getCollection(MongoDbTestConstants.COLLECTION_NAME);
assertNotNull(collection);
final FindIterable<Document> found = collection.find();
final Document first = found.first();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.logging.log4j.mongodb3;
package org.apache.logging.log4j.mongodb;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.apache.logging.log4j.Logger;
Expand All @@ -28,17 +28,17 @@
import org.bson.Document;
import org.junit.jupiter.api.Test;

@UsingMongoDb3
@UsingMongoDb
@LoggerContextSource("log4j2-mongodb-auth-failure.xml")
public class MongoDb3AuthFailureTest {
public class MongoDbAuthFailureTest {

@Test
public void test(final LoggerContext ctx, final MongoClient mongoClient) {
final Logger logger = ctx.getLogger(MongoDb3AuthFailureTest.class);
final Logger logger = ctx.getLogger(MongoDbAuthFailureTest.class);
logger.info("Hello log");
final MongoDatabase database = mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME);
final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
assertNotNull(database);
final MongoCollection<Document> collection = database.getCollection(MongoDb3TestConstants.DATABASE_NAME);
final MongoCollection<Document> collection = database.getCollection(MongoDbTestConstants.DATABASE_NAME);
assertNotNull(collection);
final Document first = collection.find().first();
assertNull(first);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.logging.log4j.mongodb3;
package org.apache.logging.log4j.mongodb;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.apache.logging.log4j.Logger;
Expand All @@ -27,20 +27,20 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

@UsingMongoDb3
@UsingMongoDb
@LoggerContextSource("log4j2-mongodb-map-message.xml")
public class MongoDb3MapMessageTest {
public class MongoDbMapMessageTest {

@Test
public void test(final LoggerContext ctx, final MongoClient mongoClient) {
final Logger logger = ctx.getLogger(MongoDb3MapMessageTest.class);
final Logger logger = ctx.getLogger(MongoDbMapMessageTest.class);
final MapMessage<?, Object> mapMessage = new MapMessage<>();
mapMessage.with("SomeName", "SomeValue");
mapMessage.with("SomeInt", 1);
logger.info(mapMessage);
final MongoDatabase database = mongoClient.getDatabase(MongoDb3TestConstants.DATABASE_NAME);
final MongoDatabase database = mongoClient.getDatabase(MongoDbTestConstants.DATABASE_NAME);
Assertions.assertNotNull(database);
final MongoCollection<Document> collection = database.getCollection(MongoDb3TestConstants.COLLECTION_NAME);
final MongoCollection<Document> collection = database.getCollection(MongoDbTestConstants.COLLECTION_NAME);
Assertions.assertNotNull(collection);
final Document first = collection.find().first();
Assertions.assertNotNull(first);
Expand Down
Loading