You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2018/01/22 15:40:41 UTC
[1/2] logging-log4j2 git commit: [LOG4J2-2209] Rename existing
MongoDb plugin and related artifacts from MongoDb to MongoDb2.
Repository: logging-log4j2
Updated Branches:
refs/heads/master ae7c4cbca -> 27337afe7
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/MongoDbObject.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/MongoDbObject.java b/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/MongoDbObject.java
new file mode 100644
index 0000000..28a35cd
--- /dev/null
+++ b/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/MongoDbObject.java
@@ -0,0 +1,66 @@
+/*
+ * 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.mongodb2;
+
+import java.util.Collections;
+
+import org.apache.logging.log4j.core.appender.nosql.NoSqlObject;
+
+import com.mongodb.BasicDBList;
+import com.mongodb.BasicDBObject;
+
+/**
+ * The MongoDB implementation of {@link NoSqlObject}.
+ */
+public final class MongoDbObject implements NoSqlObject<BasicDBObject> {
+ private final BasicDBObject mongoObject;
+
+ public MongoDbObject() {
+ this.mongoObject = new BasicDBObject();
+ }
+
+ @Override
+ public void set(final String field, final NoSqlObject<BasicDBObject> value) {
+ this.mongoObject.append(field, value.unwrap());
+ }
+
+ @Override
+ public void set(final String field, final NoSqlObject<BasicDBObject>[] values) {
+ final BasicDBList list = new BasicDBList();
+ for (final NoSqlObject<BasicDBObject> value : values) {
+ list.add(value.unwrap());
+ }
+ this.mongoObject.append(field, list);
+ }
+
+ @Override
+ public void set(final String field, final Object value) {
+ this.mongoObject.append(field, value);
+ }
+
+ @Override
+ public void set(final String field, final Object[] values) {
+ final BasicDBList list = new BasicDBList();
+ Collections.addAll(list, values);
+ this.mongoObject.append(field, list);
+ }
+
+ @Override
+ public BasicDBObject unwrap() {
+ return this.mongoObject;
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/MongoDbProvider.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/MongoDbProvider.java b/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/MongoDbProvider.java
new file mode 100644
index 0000000..d5d4aa9
--- /dev/null
+++ b/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/MongoDbProvider.java
@@ -0,0 +1,352 @@
+/*
+ * 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.mongodb2;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+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.PluginAliases;
+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.core.util.NameUtil;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.LoaderUtil;
+import org.apache.logging.log4j.util.Strings;
+
+import com.mongodb.DB;
+import com.mongodb.MongoClient;
+import com.mongodb.MongoCredential;
+import com.mongodb.ServerAddress;
+import com.mongodb.WriteConcern;
+
+/**
+ * The MongoDB implementation of {@link NoSqlProvider}.
+ */
+@Plugin(name = "MongoDb2", category = Core.CATEGORY_NAME, printObject = true)
+@PluginAliases("MongoDb") // Deprecated alias
+public final class MongoDbProvider implements NoSqlProvider<MongoDbConnection> {
+
+ public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B>
+ implements org.apache.logging.log4j.core.util.Builder<MongoDbProvider> {
+
+ 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
+ @ValidHost
+ private String server = "localhost";
+
+ @PluginBuilderAttribute
+ @ValidPort
+ private String port = "" + DEFAULT_PORT;
+
+ @PluginBuilderAttribute
+ @Required(message = "No database name provided")
+ private String databaseName;
+
+ @PluginBuilderAttribute
+ @Required(message = "No collection name provided")
+ private String collectionName;
+
+ @PluginBuilderAttribute
+ private String userName;
+
+ @PluginBuilderAttribute(sensitive = true)
+ private String password;
+
+ @PluginBuilderAttribute("capped")
+ private boolean isCapped = false;
+
+ @PluginBuilderAttribute
+ private int collectionSize = DEFAULT_COLLECTION_SIZE;
+
+ @PluginBuilderAttribute
+ private String factoryClassName;
+
+ @PluginBuilderAttribute
+ private String factoryMethodName;
+
+ @PluginBuilderAttribute
+ private String writeConcernConstantClassName;
+
+ @PluginBuilderAttribute
+ private String writeConcernConstant;
+
+ @Override
+ public MongoDbProvider build() {
+ DB database;
+ String description;
+ 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 DB) {
+ database = (DB) object;
+ } else if (object instanceof MongoClient) {
+ if (Strings.isNotEmpty(databaseName)) {
+ database = ((MongoClient) object).getDB(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);
+ return null;
+ } else {
+ LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}].", factoryClassName,
+ factoryMethodName, object.getClass().getName());
+ return null;
+ }
+
+ description = "database=" + database.getName();
+ final List<ServerAddress> addresses = database.getMongo().getAllAddress();
+ if (addresses.size() == 1) {
+ description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort();
+ } else {
+ description += ", servers=[";
+ for (final ServerAddress address : addresses) {
+ description += " { " + address.getHost() + ", " + address.getPort() + " } ";
+ }
+ description += "]";
+ }
+ } 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)) {
+ final List<MongoCredential> credentials = new ArrayList<>();
+ description = "database=" + databaseName;
+ if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) {
+ description += ", username=" + userName + ", passwordHash="
+ + NameUtil.md5(password + MongoDbProvider.class.getName());
+ credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray()));
+ }
+ try {
+ final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT);
+ description += ", server=" + server + ", port=" + portInt;
+ database = new MongoClient(new ServerAddress(server, portInt), credentials).getDB(databaseName);
+ } catch (final Exception e) {
+ LOGGER.error(
+ "Failed to obtain a database instance from the MongoClient at server [{}] and " + "port [{}].",
+ server, port);
+ return null;
+ }
+ } else {
+ LOGGER.error("No factory method was provided so the database name is required.");
+ return null;
+ }
+
+ try {
+ database.getCollectionNames(); // 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);
+ return null;
+ }
+
+ final WriteConcern writeConcern = toWriteConcern(writeConcernConstant, writeConcernConstantClassName);
+
+ return new MongoDbProvider(database, writeConcern, collectionName, isCapped, collectionSize, description);
+ }
+
+ public B setCapped(final boolean isCapped) {
+ this.isCapped = 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 WriteConcern DEFAULT_WRITE_CONCERN = WriteConcern.ACKNOWLEDGED;
+ private static final Logger LOGGER = StatusLogger.getLogger();
+ private static final int DEFAULT_PORT = 27017;
+
+ private static final int DEFAULT_COLLECTION_SIZE = 536870912;
+ /**
+ * Factory method for creating a MongoDB provider within the plugin manager.
+ *
+ * @param collectionName The name of the MongoDB collection to which log events should be written.
+ * @param writeConcernConstant The {@link WriteConcern} constant to control writing details, defaults to
+ * {@link WriteConcern#ACKNOWLEDGED}.
+ * @param writeConcernConstantClassName The name of a class containing the aforementioned static WriteConcern
+ * constant. Defaults to {@link WriteConcern}.
+ * @param databaseName The name of the MongoDB database containing the collection to which log events should be
+ * written. Mutually exclusive with {@code factoryClassName&factoryMethodName!=null}.
+ * @param server The host name of the MongoDB server, defaults to localhost and mutually exclusive with
+ * {@code factoryClassName&factoryMethodName!=null}.
+ * @param port The port the MongoDB server is listening on, defaults to the default MongoDB port and mutually
+ * exclusive with {@code factoryClassName&factoryMethodName!=null}.
+ * @param userName The username to authenticate against the MongoDB server with.
+ * @param password The password to authenticate against the MongoDB server with.
+ * @param factoryClassName A fully qualified class name containing a static factory method capable of returning a
+ * {@link DB} or a {@link MongoClient}.
+ * @param factoryMethodName The name of the public static factory method belonging to the aforementioned factory
+ * class.
+ * @return a new MongoDB provider.
+ * @deprecated in 2.8; use {@link #newBuilder()} instead.
+ */
+ @Deprecated
+ public static MongoDbProvider createNoSqlProvider(
+ final String collectionName,
+ final String writeConcernConstant,
+ final String writeConcernConstantClassName,
+ final String databaseName,
+ final String server,
+ final String port,
+ final String userName,
+ final String password,
+ final String factoryClassName,
+ final String factoryMethodName) {
+ LOGGER.info("createNoSqlProvider");
+ return newBuilder().setCollectionName(collectionName).setWriteConcernConstant(writeConcernConstantClassName)
+ .setWriteConcernConstant(writeConcernConstant).setDatabaseName(databaseName).setServer(server)
+ .setPort(port).setUserName(userName).setPassword(password).setFactoryClassName(factoryClassName)
+ .setFactoryMethodName(factoryMethodName).build();
+ }
+ @PluginBuilderFactory
+ public static <B extends Builder<B>> B newBuilder() {
+ return new Builder<B>().asBuilder();
+ }
+ private final String collectionName;
+ private final DB database;
+ private final String description;
+
+ private final WriteConcern writeConcern;
+
+ private final boolean isCapped;
+
+ private final Integer collectionSize;
+
+ private MongoDbProvider(final DB database, final WriteConcern writeConcern, final String collectionName,
+ final boolean isCapped, final Integer collectionSize, final String description) {
+ this.database = database;
+ this.writeConcern = writeConcern;
+ this.collectionName = collectionName;
+ this.isCapped = isCapped;
+ this.collectionSize = collectionSize;
+ this.description = "mongoDb{ " + description + " }";
+ }
+
+ @Override
+ public MongoDbConnection getConnection() {
+ return new MongoDbConnection(this.database, this.writeConcern, this.collectionName, this.isCapped, this.collectionSize);
+ }
+
+ @Override
+ public String toString() {
+ return this.description;
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/package-info.java b/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/package-info.java
new file mode 100644
index 0000000..bf111af
--- /dev/null
+++ b/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+package org.apache.logging.log4j.mongodb2;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/site/markdown/index.md.vm
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/site/markdown/index.md.vm b/log4j-mongodb2/src/site/markdown/index.md.vm
new file mode 100644
index 0000000..0d1eb7a
--- /dev/null
+++ b/log4j-mongodb2/src/site/markdown/index.md.vm
@@ -0,0 +1,48 @@
+<!-- vim: set syn=markdown : -->
+<!--
+ 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.
+-->
+#set($h1='#')
+#set($h2='##')
+## TODO: use properties for dynamic dependency versions
+
+$h1 MongoDB appender
+
+[MongoDB](http://www.mongodb.org/) is supported through the
+[Java MongoDB Driver](http://docs.mongodb.org/ecosystem/drivers/java/).
+
+```
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.mongodb</groupId>
+ <artifactId>mongo-java-driver</artifactId>
+ <version>2.14.3</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.mongodb</groupId>
+ <artifactId>mongo-java-driver</artifactId>
+ </dependency>
+ </dependencies>
+```
+
+$h2 Requirements
+
+The MongoDB Appender is dependent on the Log4j 2 API and implementation.
+For more information, see [Runtime Dependencies](../runtime-dependencies.html).
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/site/site.xml
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/site/site.xml b/log4j-mongodb2/src/site/site.xml
new file mode 100644
index 0000000..f5db26e
--- /dev/null
+++ b/log4j-mongodb2/src/site/site.xml
@@ -0,0 +1,52 @@
+<!--
+ 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.
+
+-->
+<project name="Log4j MongoDB 2.x Appender"
+ xmlns="http://maven.apache.org/DECORATION/1.4.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/DECORATION/1.4.0 http://maven.apache.org/xsd/decoration-1.4.0.xsd">
+ <body>
+ <links>
+ <item name="Apache" href="http://www.apache.org/" />
+ <item name="Logging Services" href="http://logging.apache.org/"/>
+ <item name="Log4j" href="../index.html"/>
+ </links>
+
+ <!-- Component-specific reports -->
+ <menu ref="reports"/>
+
+ <!-- Overall Project Info -->
+ <menu name="Log4j Project Information" img="icon-info-sign">
+ <item name="Dependencies" href="../dependencies.html" />
+ <item name="Dependency Convergence" href="../dependency-convergence.html" />
+ <item name="Dependency Management" href="../dependency-management.html" />
+ <item name="Project Team" href="../team-list.html" />
+ <item name="Mailing Lists" href="../mail-lists.html" />
+ <item name="Issue Tracking" href="../issue-tracking.html" />
+ <item name="Project License" href="../license.html" />
+ <item name="Source Repository" href="../source-repository.html" />
+ <item name="Project Summary" href="../project-summary.html" />
+ </menu>
+
+ <menu name="Log4j Project Reports" img="icon-cog">
+ <item name="Changes Report" href="../changes-report.html" />
+ <item name="JIRA Report" href="../jira-report.html" />
+ <item name="Surefire Report" href="../surefire-report.html" />
+ <item name="RAT Report" href="../rat-report.html" />
+ </menu>
+ </body>
+</project>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/Java8Test.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/Java8Test.java b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/Java8Test.java
new file mode 100644
index 0000000..569cf4a
--- /dev/null
+++ b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/Java8Test.java
@@ -0,0 +1,48 @@
+/*
+ * 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.mongodb2;
+
+import org.apache.commons.lang3.JavaVersion;
+import org.apache.commons.lang3.SystemUtils;
+import org.junit.Assume;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Runs all MongoDB only on Java 8.
+ * <p>
+ * The test framework {@code de.flapdoodle.embed.mongo} requires Java 8.
+ * </p>
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({ MongoDbTestTestRuleTestJava8.class, MongoDbAuthFailureTestJava8.class, MongoDbCappedTestJava8.class,
+ MongoDbMapMessageTestJava8.class, MongoDbTestJava8.class })
+public class Java8Test {
+
+ @BeforeClass
+ public static void beforeClass() {
+ Assume.assumeTrue(SystemUtils.JAVA_VERSION, SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8));
+ }
+
+ @Test
+ public void test() {
+ // noop
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbAuthFailureTestJava8.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbAuthFailureTestJava8.java b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbAuthFailureTestJava8.java
new file mode 100644
index 0000000..903265c
--- /dev/null
+++ b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbAuthFailureTestJava8.java
@@ -0,0 +1,70 @@
+/*
+ * 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.mongodb2;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.categories.Appenders;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.mongodb2.MongoDbTestRule.LoggingTarget;
+import org.apache.logging.log4j.test.AvailablePortSystemPropertyTestRule;
+import org.apache.logging.log4j.test.RuleChainFactory;
+import org.junit.Assert;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.RuleChain;
+
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.MongoClient;
+
+/**
+ * This class name does NOT end in "Test" in order to only be picked up by {@link Java8Test}.
+ *
+ * TODO set up the log4j user in MongoDB.
+ */
+@Category(Appenders.MongoDb.class)
+public class MongoDbAuthFailureTestJava8 {
+
+ private static LoggerContextRule loggerContextTestRule = new LoggerContextRule("log4j2-mongodb-auth-failure.xml");
+
+ private static final AvailablePortSystemPropertyTestRule mongoDbPortTestRule = AvailablePortSystemPropertyTestRule
+ .create(TestConstants.SYS_PROP_NAME_PORT);
+
+ private static final MongoDbTestRule mongoDbTestRule = new MongoDbTestRule(mongoDbPortTestRule.getName(), LoggingTarget.NULL);
+
+ @ClassRule
+ public static RuleChain ruleChain = RuleChainFactory.create(mongoDbPortTestRule, mongoDbTestRule,
+ loggerContextTestRule);
+
+ @Test
+ public void test() {
+ final Logger logger = LogManager.getLogger();
+ logger.info("Hello log");
+ final MongoClient mongoClient = mongoDbTestRule.getMongoClient();
+ try {
+ final DB database = mongoClient.getDB("test");
+ Assert.assertNotNull(database);
+ final DBCollection collection = database.getCollection("applog");
+ Assert.assertNotNull(collection);
+ Assert.assertFalse(collection.find().hasNext());
+ } finally {
+ mongoClient.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbCappedTestJava8.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbCappedTestJava8.java b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbCappedTestJava8.java
new file mode 100644
index 0000000..03e463a
--- /dev/null
+++ b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbCappedTestJava8.java
@@ -0,0 +1,72 @@
+/*
+ * 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.mongodb2;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.categories.Appenders;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.mongodb2.MongoDbTestRule.LoggingTarget;
+import org.apache.logging.log4j.test.AvailablePortSystemPropertyTestRule;
+import org.apache.logging.log4j.test.RuleChainFactory;
+import org.junit.Assert;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.RuleChain;
+
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.MongoClient;
+
+/**
+ * This class name does NOT end in "Test" in order to only be picked up by {@link Java8Test}.
+ */
+@Category(Appenders.MongoDb.class)
+public class MongoDbCappedTestJava8 {
+
+ private static LoggerContextRule loggerContextTestRule = new LoggerContextRule("log4j2-mongodb-capped.xml");
+
+ private static final AvailablePortSystemPropertyTestRule mongoDbPortTestRule = AvailablePortSystemPropertyTestRule
+ .create(TestConstants.SYS_PROP_NAME_PORT);
+
+ private static final MongoDbTestRule mongoDbTestRule = new MongoDbTestRule(mongoDbPortTestRule.getName(), LoggingTarget.NULL);
+
+ @ClassRule
+ public static RuleChain ruleChain = RuleChainFactory.create(mongoDbPortTestRule, mongoDbTestRule,
+ loggerContextTestRule);
+
+ @Test
+ public void test() {
+ final Logger logger = LogManager.getLogger();
+ logger.info("Hello log");
+ final MongoClient mongoClient = mongoDbTestRule.getMongoClient();
+ try {
+ final DB database = mongoClient.getDB("test");
+ Assert.assertNotNull(database);
+ final DBCollection collection = database.getCollection("applog");
+ Assert.assertNotNull(collection);
+ Assert.assertTrue(collection.find().hasNext());
+ final DBObject first = collection.find().next();
+ Assert.assertNotNull(first);
+ Assert.assertEquals(first.toMap().toString(), "Hello log", first.get("message"));
+ } finally {
+ mongoClient.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbMapMessageTestJava8.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbMapMessageTestJava8.java b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbMapMessageTestJava8.java
new file mode 100644
index 0000000..03622ba
--- /dev/null
+++ b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbMapMessageTestJava8.java
@@ -0,0 +1,77 @@
+/*
+ * 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.mongodb2;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.categories.Appenders;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.message.MapMessage;
+import org.apache.logging.log4j.mongodb2.MongoDbTestRule.LoggingTarget;
+import org.apache.logging.log4j.test.AvailablePortSystemPropertyTestRule;
+import org.apache.logging.log4j.test.RuleChainFactory;
+import org.junit.Assert;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.RuleChain;
+
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.MongoClient;
+
+/**
+ * This class name does NOT end in "Test" in order to only be picked up by {@link Java8Test}.
+ */
+@Category(Appenders.MongoDb.class)
+public class MongoDbMapMessageTestJava8 {
+
+ private static LoggerContextRule loggerContextTestRule = new LoggerContextRule("log4j2-mongodb-map-message.xml");
+
+ private static final AvailablePortSystemPropertyTestRule mongoDbPortTestRule = AvailablePortSystemPropertyTestRule
+ .create(TestConstants.SYS_PROP_NAME_PORT);
+
+ private static final MongoDbTestRule mongoDbTestRule = new MongoDbTestRule(mongoDbPortTestRule.getName(), LoggingTarget.NULL);
+
+ @ClassRule
+ public static RuleChain ruleChain = RuleChainFactory.create(mongoDbPortTestRule, mongoDbTestRule,
+ loggerContextTestRule);
+
+ @Test
+ public void test() {
+ final Logger logger = LogManager.getLogger();
+ final MapMessage<?,?> mapMessage = new MapMessage<>();
+ mapMessage.with("SomeName", "SomeValue");
+ mapMessage.with("SomeInt", 1);
+ logger.info(mapMessage);
+ //
+ final MongoClient mongoClient = mongoDbTestRule.getMongoClient();
+ try {
+ final DB database = mongoClient.getDB("test");
+ Assert.assertNotNull(database);
+ final DBCollection collection = database.getCollection("applog");
+ Assert.assertNotNull(collection);
+ final DBObject first = collection.find().next();
+ Assert.assertNotNull(first);
+ Assert.assertEquals(first.toMap().toString(), "SomeValue", first.get("SomeName"));
+ Assert.assertEquals(first.toMap().toString(), Integer.valueOf(1), first.get("SomeInt"));
+ } finally {
+ mongoClient.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbTestJava8.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbTestJava8.java b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbTestJava8.java
new file mode 100644
index 0000000..0e26610
--- /dev/null
+++ b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbTestJava8.java
@@ -0,0 +1,71 @@
+/*
+ * 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.mongodb2;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.categories.Appenders;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.mongodb2.MongoDbTestRule.LoggingTarget;
+import org.apache.logging.log4j.test.AvailablePortSystemPropertyTestRule;
+import org.apache.logging.log4j.test.RuleChainFactory;
+import org.junit.Assert;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.RuleChain;
+
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.MongoClient;
+
+/**
+ * This class name does NOT end in "Test" in order to only be picked up by {@link Java8Test}.
+ */
+@Category(Appenders.MongoDb.class)
+public class MongoDbTestJava8 {
+
+ private static LoggerContextRule loggerContextTestRule = new LoggerContextRule("log4j2-mongodb.xml");
+
+ private static final AvailablePortSystemPropertyTestRule mongoDbPortTestRule = AvailablePortSystemPropertyTestRule
+ .create(TestConstants.SYS_PROP_NAME_PORT);
+
+ private static final MongoDbTestRule mongoDbTestRule = new MongoDbTestRule(mongoDbPortTestRule.getName(), LoggingTarget.NULL);
+
+ @ClassRule
+ public static RuleChain ruleChain = RuleChainFactory.create(mongoDbPortTestRule, mongoDbTestRule,
+ loggerContextTestRule);
+
+ @Test
+ public void test() {
+ final Logger logger = LogManager.getLogger();
+ logger.info("Hello log");
+ final MongoClient mongoClient = mongoDbTestRule.getMongoClient();
+ try {
+ final DB database = mongoClient.getDB("test");
+ Assert.assertNotNull(database);
+ final DBCollection collection = database.getCollection("applog");
+ Assert.assertNotNull(collection);
+ final DBObject first = collection.find().next();
+ Assert.assertNotNull(first);
+ Assert.assertEquals(first.toMap().toString(), "Hello log", first.get("message"));
+ } finally {
+ mongoClient.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbTestRule.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbTestRule.java b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbTestRule.java
new file mode 100644
index 0000000..f65c8ad
--- /dev/null
+++ b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbTestRule.java
@@ -0,0 +1,178 @@
+/*
+ * 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.mongodb2;
+
+import java.util.Objects;
+
+import org.apache.commons.lang3.NotImplementedException;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.mongodb.MongoClient;
+
+import de.flapdoodle.embed.mongo.Command;
+import de.flapdoodle.embed.mongo.MongodExecutable;
+import de.flapdoodle.embed.mongo.MongodProcess;
+import de.flapdoodle.embed.mongo.MongodStarter;
+import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
+import de.flapdoodle.embed.mongo.config.Net;
+import de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder;
+import de.flapdoodle.embed.mongo.config.Timeout;
+import de.flapdoodle.embed.mongo.distribution.Version;
+import de.flapdoodle.embed.process.config.IRuntimeConfig;
+import de.flapdoodle.embed.process.config.io.ProcessOutput;
+import de.flapdoodle.embed.process.runtime.Network;
+
+/**
+ * A JUnit test rule to manage a MongoDB embedded instance.
+ */
+public class MongoDbTestRule implements TestRule {
+
+ public enum LoggingTarget {
+ NULL, CONSOLE
+ }
+
+ private static final int BUILDER_TIMEOUT_MILLIS = 30000;
+
+ public static int getBuilderTimeoutMillis() {
+ return BUILDER_TIMEOUT_MILLIS;
+ }
+
+ /**
+ * Store {@link MongodStarter} (or RuntimeConfig) in a static final field if you want to use artifact store caching
+ * (or else disable caching).
+ * <p>
+ * The test framework {@code de.flapdoodle.embed.mongo} requires Java 8.
+ * </p>
+ */
+ protected final MongodStarter starter;
+
+ protected final String portSystemPropertyName;
+
+ protected MongoClient mongoClient;
+ protected MongodExecutable mongodExecutable;
+ protected MongodProcess mongodProcess;
+ protected final LoggingTarget loggingTarget;
+
+ /**
+ * Constructs a new test rule.
+ *
+ * @param portSystemPropertyName
+ * The system property name for the MongoDB port.
+ * @param loggingTarget
+ * The logging target
+ */
+ public MongoDbTestRule(final String portSystemPropertyName, final LoggingTarget loggingTarget) {
+ this.portSystemPropertyName = Objects.requireNonNull(portSystemPropertyName, "portSystemPropertyName");
+ this.loggingTarget = loggingTarget;
+ this.starter = getMongodStarter(loggingTarget);
+ }
+
+ private static MongodStarter getMongodStarter(final LoggingTarget loggingTarget) {
+ if (loggingTarget == null) {
+ return MongodStarter.getDefaultInstance();
+ }
+ switch (loggingTarget) {
+ case NULL:
+ final Logger logger = LoggerFactory.getLogger(MongoDbTestRule.class.getName());
+ final IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
+ // @formatter:off
+ .defaultsWithLogger(Command.MongoD, logger)
+ .processOutput(ProcessOutput.getDefaultInstanceSilent())
+ .build();
+ // @formatter:on
+
+ return MongodStarter.getInstance(runtimeConfig);
+ case CONSOLE:
+ return MongodStarter.getDefaultInstance();
+ default:
+ throw new NotImplementedException(loggingTarget.toString());
+ }
+ }
+
+ @Override
+ public Statement apply(final Statement base, final Description description) {
+ return new Statement() {
+
+ @Override
+ public void evaluate() throws Throwable {
+ final String value = Objects.requireNonNull(System.getProperty(portSystemPropertyName),
+ "System property '" + portSystemPropertyName + "' is null");
+ final int port = Integer.parseInt(value);
+ mongodExecutable = starter.prepare(
+ // @formatter:off
+ new MongodConfigBuilder()
+ .version(Version.Main.PRODUCTION)
+ .timeout(new Timeout(BUILDER_TIMEOUT_MILLIS))
+ .net(
+ new Net("localhost", port, Network.localhostIsIPv6()))
+ .build());
+ // @formatter:on
+ mongodProcess = mongodExecutable.start();
+ mongoClient = new MongoClient("localhost", port);
+ try {
+ base.evaluate();
+ } finally {
+ if (mongodProcess != null) {
+ mongodProcess.stop();
+ mongodProcess = null;
+ }
+ if (mongodExecutable != null) {
+ mongodExecutable.stop();
+ mongodExecutable = null;
+ }
+ }
+ }
+ };
+ }
+
+ public MongoClient getMongoClient() {
+ return mongoClient;
+ }
+
+ public MongodExecutable getMongodExecutable() {
+ return mongodExecutable;
+ }
+
+ public MongodProcess getMongodProcess() {
+ return mongodProcess;
+ }
+
+ public MongodStarter getStarter() {
+ return starter;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("MongoDbTestRule [portSystemPropertyName=");
+ builder.append(portSystemPropertyName);
+ builder.append(", mongoClient=");
+ builder.append(mongoClient);
+ builder.append(", mongodExecutable=");
+ builder.append(mongodExecutable);
+ builder.append(", mongodProcess=");
+ builder.append(mongodProcess);
+ builder.append("]");
+ return builder.toString();
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbTestTestRuleTestJava8.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbTestTestRuleTestJava8.java b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbTestTestRuleTestJava8.java
new file mode 100644
index 0000000..0230cc0
--- /dev/null
+++ b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/MongoDbTestTestRuleTestJava8.java
@@ -0,0 +1,71 @@
+/*
+ * 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.mongodb2;
+
+import java.util.List;
+
+import org.apache.commons.lang3.JavaVersion;
+import org.apache.commons.lang3.SystemUtils;
+import org.apache.logging.log4j.mongodb2.MongoDbTestRule.LoggingTarget;
+import org.apache.logging.log4j.test.AvailablePortSystemPropertyTestRule;
+import org.apache.logging.log4j.test.RuleChainFactory;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+
+/**
+ * Tests MongoDbRule. This class name does NOT end in "Test" in order to only be picked up by {@link Java8Test}.
+ * <p>
+ * The test framework {@code de.flapdoodle.embed.mongo} requires Java 8.
+ * </p>
+ */
+public class MongoDbTestTestRuleTestJava8 {
+
+ private static final AvailablePortSystemPropertyTestRule mongoDbPortTestRule = AvailablePortSystemPropertyTestRule
+ .create(TestConstants.SYS_PROP_NAME_PORT);
+
+ private static final MongoDbTestRule mongoDbTestRule = new MongoDbTestRule(mongoDbPortTestRule.getName(), LoggingTarget.NULL);
+
+ @ClassRule
+ public static RuleChain mongoDbChain = RuleChainFactory.create(mongoDbPortTestRule, mongoDbTestRule);
+
+ @BeforeClass
+ public static void beforeClass() {
+ Assume.assumeTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8));
+ }
+
+ @Test
+ public void testAccess() {
+ final List<String> databaseNames = mongoDbTestRule.getMongoClient().getDatabaseNames();
+ Assert.assertNotNull(databaseNames);
+ Assert.assertFalse(databaseNames.isEmpty());
+ Assert.assertNotNull(databaseNames.get(0));
+ }
+
+ @Test
+ public void testMongoDbTestRule() {
+ Assert.assertNotNull(mongoDbTestRule);
+ Assert.assertNotNull(mongoDbTestRule.getStarter());
+ Assert.assertNotNull(mongoDbTestRule.getMongoClient());
+ Assert.assertNotNull(mongoDbTestRule.getMongodExecutable());
+ Assert.assertNotNull(mongoDbTestRule.getMongodProcess());
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/TestConstants.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/TestConstants.java b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/TestConstants.java
new file mode 100644
index 0000000..040209c
--- /dev/null
+++ b/log4j-mongodb2/src/test/java/org/apache/logging/log4j/mongodb2/TestConstants.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.mongodb2;
+
+public class TestConstants {
+
+ public static final String SYS_PROP_NAME_PORT = "MongoDBTestPort";
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/test/resources/log4j2-mongodb-auth-failure.xml
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/test/resources/log4j2-mongodb-auth-failure.xml b/log4j-mongodb2/src/test/resources/log4j2-mongodb-auth-failure.xml
new file mode 100644
index 0000000..43d7e37
--- /dev/null
+++ b/log4j-mongodb2/src/test/resources/log4j2-mongodb-auth-failure.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<Configuration status="WARN">
+ <Appenders>
+ <NoSql name="MongoDbAppender">
+ <MongoDb2 databaseName="test" collectionName="applog" server="localhost" userName="log4jUser" password="12345678"
+ port="${sys:MongoDBTestPort:-27017}" />
+ </NoSql>
+ </Appenders>
+ <Loggers>
+ <Root level="ALL">
+ <AppenderRef ref="MongoDbAppender" />
+ </Root>
+ </Loggers>
+</Configuration>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/test/resources/log4j2-mongodb-capped.xml
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/test/resources/log4j2-mongodb-capped.xml b/log4j-mongodb2/src/test/resources/log4j2-mongodb-capped.xml
new file mode 100644
index 0000000..7eda0ae
--- /dev/null
+++ b/log4j-mongodb2/src/test/resources/log4j2-mongodb-capped.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<Configuration status="WARN">
+ <Appenders>
+ <NoSql name="MongoDbAppender">
+ <MongoDb2 databaseName="test" collectionName="applog" server="localhost" capped="true" collectionSize="1073741824"
+ port="${sys:MongoDBTestPort:-27017}" />
+ </NoSql>
+ </Appenders>
+ <Loggers>
+ <Root level="ALL">
+ <AppenderRef ref="MongoDbAppender" />
+ </Root>
+ </Loggers>
+</Configuration>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/test/resources/log4j2-mongodb-map-message.xml
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/test/resources/log4j2-mongodb-map-message.xml b/log4j-mongodb2/src/test/resources/log4j2-mongodb-map-message.xml
new file mode 100644
index 0000000..12f957a
--- /dev/null
+++ b/log4j-mongodb2/src/test/resources/log4j2-mongodb-map-message.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<Configuration status="WARN">
+ <Appenders>
+ <NoSql name="MongoDbAppender">
+ <MongoDb2 databaseName="test" collectionName="applog" server="localhost"
+ port="${sys:MongoDBTestPort:-27017}" />
+ <MessageLayout />
+ </NoSql>
+ </Appenders>
+ <Loggers>
+ <Root level="ALL">
+ <AppenderRef ref="MongoDbAppender" />
+ </Root>
+ </Loggers>
+</Configuration>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/test/resources/log4j2-mongodb.xml
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/test/resources/log4j2-mongodb.xml b/log4j-mongodb2/src/test/resources/log4j2-mongodb.xml
new file mode 100644
index 0000000..805c746
--- /dev/null
+++ b/log4j-mongodb2/src/test/resources/log4j2-mongodb.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<Configuration status="WARN">
+ <Appenders>
+ <NoSql name="MongoDbAppender">
+ <MongoDb2 databaseName="test" collectionName="applog" server="localhost"
+ port="${sys:MongoDBTestPort:-27017}" />
+ </NoSql>
+ </Appenders>
+ <Loggers>
+ <Root level="ALL">
+ <AppenderRef ref="MongoDbAppender" />
+ </Root>
+ </Loggers>
+</Configuration>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index ca46e4a..a17e3a6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -186,7 +186,8 @@
<flumeVersion>1.7.0</flumeVersion> <!-- Version 1.8.0 requires Java 8 -->
<disruptorVersion>3.3.7</disruptorVersion>
<conversantDisruptorVersion>1.2.10</conversantDisruptorVersion> <!-- Version 1.2.11 requires Java 8 -->
- <mongodb.version>3.6.1</mongodb.version>
+ <mongodb2.version>2.14.3</mongodb2.version>
+ <mongodb3.version>3.6.1</mongodb3.version>
<compiler.plugin.version>3.7.0</compiler.plugin.version>
<pmd.plugin.version>3.8</pmd.plugin.version>
<findbugs.plugin.version>3.0.5</findbugs.plugin.version>
@@ -730,13 +731,18 @@
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
+ <artifactId>mongo-java-driver</artifactId>
+ <version>${mongodb2.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
- <version>${mongodb.version}</version>
+ <version>${mongodb3.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
- <version>${mongodb.version}</version>
+ <version>${mongodb3.version}</version>
</dependency>
<dependency>
<groupId>org.lightcouch</groupId>
@@ -1322,7 +1328,8 @@
<module>log4j-bom</module>
<module>log4j-jdbc-dbcp2</module>
<module>log4j-couchdb</module>
- <module>log4j-mongodb</module>
+ <module>log4j-mongodb2</module>
+ <!-- <module>log4j-mongodb3</module> -->
<module>log4j-cassandra</module>
<module>log4j-web</module>
<module>log4j-perf</module>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index e460b96..f5646b1 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -125,6 +125,9 @@
<action issue="LOG4J2-2208" dev="ggregory" type="add">
Add debug logging to org.apache.logging.log4j.mongodb.MongoDbConnection.
</action>
+ <action issue="LOG4J2-2209" dev="ggregory" type="update">
+ Rename existing MongoDb plugin and related artifacts from MongoDb to MongoDb2.
+ </action>
</release>
<release version="2.10.0" date="2017-11-18" description="GA Release 2.10.0">
<action issue="LOG4J2-2120" dev="mikes" type="add" due-to="Carter Douglas Kozak ">
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/src/site/site.xml
----------------------------------------------------------------------
diff --git a/src/site/site.xml b/src/site/site.xml
index f4b1498..d84b09e 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -138,7 +138,7 @@
<item name="Kafka" href="/manual/appenders.html#KafkaAppender"/>
<item name="Memory Mapped File" href="/manual/appenders.html#MemoryMappedFileAppender"/>
<item name="NoSQL" href="/manual/appenders.html#NoSQLAppender"/>
- <item name="NoSQL for MongoDB" href="/manual/appenders.html#NoSQLAppenderMongoDB"/>
+ <item name="NoSQL for MongoDB 2" href="/manual/appenders.html#NoSQLAppenderMongoDB2"/>
<item name="NoSQL for CouchDB" href="/manual/appenders.html#NoSQLAppenderCouchDB"/>
<item name="Output Stream" href="/manual/appenders.html#OutputStreamAppender"/>
<item name="Random Access File" href="/manual/appenders.html#RandomAccessFileAppender"/>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/src/site/xdoc/manual/appenders.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/appenders.xml b/src/site/xdoc/manual/appenders.xml
index 4f106df..25b456c 100644
--- a/src/site/xdoc/manual/appenders.xml
+++ b/src/site/xdoc/manual/appenders.xml
@@ -2225,14 +2225,15 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
]
}]]></pre>
</subsection>
- <a name="NoSQLAppenderMongoDB"/>
- <subsection name="NoSQLAppender for MongoDB">
+ <a name="NoSQLAppenderMongoDB2"/>
+ <subsection name="NoSQLAppender for MongoDB 2">
<p>
- This section details specializations of the <a href="#NoSQLAppender">NoSQLAppender</a> provider for MongoDB.
- The NoSQLAppender Appender writes log events to a NoSQL database using an internal lightweight provider interface.
+ This section details specializations of the <a href="#NoSQLAppender">NoSQLAppender</a> provider for MongoDB using
+ the MongoDB driver version 2. The NoSQLAppender Appender writes log events to a NoSQL database using an
+ internal lightweight provider interface.
</p>
<table>
- <caption align="top">MongoDB Provider Parameters</caption>
+ <caption align="top">MongoDB2 Provider Parameters</caption>
<tr>
<th>Parameter Name</th>
<th>Type</th>
@@ -2318,14 +2319,14 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
This appender is <a href="messages.html#MapMessage">MapMessage</a>-aware.
</p>
<p>
- Here are a few sample configurations for the NoSQLAppender and MongoDB provider:
+ Here are a few sample configurations for the NoSQLAppender and MongoDB2 provider:
</p>
<pre class="prettyprint linenums lang-xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="error">
<Appenders>
<NoSql name="databaseAppender">
- <MongoDb databaseName="applicationDb" collectionName="applicationLog" server="mongo.example.org"
+ <MongoDb2 databaseName="applicationDb" collectionName="applicationLog" server="mongo.example.org"
username="loggingUser" password="abc123" />
</NoSql>
</Appenders>
@@ -2340,7 +2341,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<Configuration status="error">
<Appenders>
<NoSql name="databaseAppender">
- <MongoDb collectionName="applicationLog" factoryClassName="org.example.db.ConnectionFactory"
+ <MongoDb2 collectionName="applicationLog" factoryClassName="org.example.db.ConnectionFactory"
factoryMethodName="getNewMongoClient" />
</NoSql>
</Appenders>
@@ -2350,6 +2351,10 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
</Root>
</Loggers>
</Configuration>]]></pre>
+ <p>
+ Starting in Log4j version 2.11.0, the provider element name is <code>MongoDb2</code>.
+ The name <code>MongoDb</code> is now a deprecated alias for <code>MongoDb2</code>.
+ </p>
</subsection>
<a name="NoSQLAppenderApacheCouchDB"/>
<subsection name="NoSQLAppender for Apache CouchDB">
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/src/site/xdoc/manual/messages.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/messages.xml b/src/site/xdoc/manual/messages.xml
index 41005c8..966fff6 100644
--- a/src/site/xdoc/manual/messages.xml
+++ b/src/site/xdoc/manual/messages.xml
@@ -218,7 +218,7 @@ public class MyApp {
<code>MapMessage</code> to values in a SQL INSERT statement.
</li>
<li>
- When a <a href="appenders.html#NoSQLAppenderMongoDB">MongoDB Appender</a> is configured with a <code>MessageLayout</code>, it converts a Log4j
+ When a <a href="appenders.html#NoSQLAppenderMongoDB2">MongoDB Appender</a> is configured with a <code>MessageLayout</code>, it converts a Log4j
<code>MapMessage</code> to fields in a MongoDB object.
</li>
</ul>
[2/2] logging-log4j2 git commit: [LOG4J2-2209] Rename existing
MongoDb plugin and related artifacts from MongoDb to MongoDb2.
Posted by gg...@apache.org.
[LOG4J2-2209] Rename existing MongoDb plugin and related artifacts from
MongoDb to MongoDb2.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/27337afe
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/27337afe
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/27337afe
Branch: refs/heads/master
Commit: 27337afe77cd71f71e633195ee4d5ea4669f0825
Parents: ae7c4cb
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Jan 22 08:40:30 2018 -0700
Committer: Gary Gregory <ga...@gmail.com>
Committed: Mon Jan 22 08:40:30 2018 -0700
----------------------------------------------------------------------
log4j-mongodb/pom.xml | 193 ----------
.../log4j/mongodb/MongoDbConnection.java | 103 ------
.../logging/log4j/mongodb/MongoDbObject.java | 66 ----
.../logging/log4j/mongodb/MongoDbProvider.java | 351 ------------------
.../logging/log4j/mongodb/package-info.java | 20 --
log4j-mongodb/src/site/markdown/index.md.vm | 48 ---
log4j-mongodb/src/site/site.xml | 52 ---
.../apache/logging/log4j/mongodb/Java8Test.java | 48 ---
.../mongodb/MongoDbAuthFailureTestJava8.java | 68 ----
.../log4j/mongodb/MongoDbCappedTestJava8.java | 67 ----
.../mongodb/MongoDbMapMessageTestJava8.java | 73 ----
.../logging/log4j/mongodb/MongoDbTestJava8.java | 67 ----
.../logging/log4j/mongodb/MongoDbTestRule.java | 139 --------
.../mongodb/MongoDbTestTestRuleTestJava8.java | 69 ----
.../logging/log4j/mongodb/TestConstants.java | 24 --
.../resources/log4j2-mongodb-auth-failure.xml | 31 --
.../test/resources/log4j2-mongodb-capped.xml | 31 --
.../resources/log4j2-mongodb-map-message.xml | 32 --
.../src/test/resources/log4j2-mongodb.xml | 31 --
log4j-mongodb2/pom.xml | 189 ++++++++++
.../log4j/mongodb2/MongoDbConnection.java | 103 ++++++
.../logging/log4j/mongodb2/MongoDbObject.java | 66 ++++
.../logging/log4j/mongodb2/MongoDbProvider.java | 352 +++++++++++++++++++
.../logging/log4j/mongodb2/package-info.java | 20 ++
log4j-mongodb2/src/site/markdown/index.md.vm | 48 +++
log4j-mongodb2/src/site/site.xml | 52 +++
.../logging/log4j/mongodb2/Java8Test.java | 48 +++
.../mongodb2/MongoDbAuthFailureTestJava8.java | 70 ++++
.../log4j/mongodb2/MongoDbCappedTestJava8.java | 72 ++++
.../mongodb2/MongoDbMapMessageTestJava8.java | 77 ++++
.../log4j/mongodb2/MongoDbTestJava8.java | 71 ++++
.../logging/log4j/mongodb2/MongoDbTestRule.java | 178 ++++++++++
.../mongodb2/MongoDbTestTestRuleTestJava8.java | 71 ++++
.../logging/log4j/mongodb2/TestConstants.java | 24 ++
.../resources/log4j2-mongodb-auth-failure.xml | 31 ++
.../test/resources/log4j2-mongodb-capped.xml | 31 ++
.../resources/log4j2-mongodb-map-message.xml | 32 ++
.../src/test/resources/log4j2-mongodb.xml | 31 ++
pom.xml | 15 +-
src/changes/changes.xml | 3 +
src/site/site.xml | 2 +-
src/site/xdoc/manual/appenders.xml | 21 +-
src/site/xdoc/manual/messages.xml | 2 +-
43 files changed, 1595 insertions(+), 1527 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-mongodb/pom.xml b/log4j-mongodb/pom.xml
deleted file mode 100644
index 7ffffd1..0000000
--- a/log4j-mongodb/pom.xml
+++ /dev/null
@@ -1,193 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<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">
- <parent>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>2.10.1-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>log4j-mongodb</artifactId>
- <name>Apache Log4j MongoDB Driver 2.x</name>
- <description>
- MongoDB appender for Log4j using the MongoDB 2.x driver API.
- </description>
- <properties>
- <log4jParentDir>${basedir}/..</log4jParentDir>
- <docLabel>MongoDB 2 Documentation</docLabel>
- <projectDir>/log4j-mongodb</projectDir>
- <module.name>org.apache.logging.log4j.mongodb</module.name>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>mongodb-driver</artifactId>
- </dependency>
- <dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>bson</artifactId>
- </dependency>
- <!-- Test Dependencies -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-api</artifactId>
- <type>test-jar</type>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <type>test-jar</type>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>de.flapdoodle.embed</groupId>
- <artifactId>de.flapdoodle.embed.mongo</artifactId>
- <version>2.0.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <configuration>
- <instructions>
- <Fragment-Host>org.apache.logging.log4j.core</Fragment-Host>
- <Export-Package>*</Export-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-changes-plugin</artifactId>
- <version>${changes.plugin.version}</version>
- <reportSets>
- <reportSet>
- <reports>
- <report>changes-report</report>
- </reports>
- </reportSet>
- </reportSets>
- <configuration>
- <issueLinkTemplate>%URL%/show_bug.cgi?id=%ISSUE%</issueLinkTemplate>
- <useJql>true</useJql>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <version>${checkstyle.plugin.version}</version>
- <configuration>
- <!--<propertiesLocation>${vfs.parent.dir}/checkstyle.properties</propertiesLocation> -->
- <configLocation>${log4jParentDir}/checkstyle.xml</configLocation>
- <suppressionsLocation>${log4jParentDir}/checkstyle-suppressions.xml</suppressionsLocation>
- <enableRulesSummary>false</enableRulesSummary>
- <propertyExpansion>basedir=${basedir}</propertyExpansion>
- <propertyExpansion>licensedir=${log4jParentDir}/checkstyle-header.txt</propertyExpansion>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>${javadoc.plugin.version}</version>
- <configuration>
- <bottom><![CDATA[<p align="center">Copyright © {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.<br />
- Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo,
- and the Apache Log4j logo are trademarks of The Apache Software Foundation.</p>]]></bottom>
- <!-- module link generation is completely broken in the javadoc plugin for a multi-module non-aggregating
- project -->
- <detectOfflineLinks>false</detectOfflineLinks>
- <linksource>true</linksource>
- </configuration>
- <reportSets>
- <reportSet>
- <id>non-aggregate</id>
- <reports>
- <report>javadoc</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>findbugs-maven-plugin</artifactId>
- <version>${findbugs.plugin.version}</version>
- <configuration>
- <fork>true</fork>
- <jvmArgs>-Duser.language=en</jvmArgs>
- <threshold>Normal</threshold>
- <effort>Default</effort>
- <excludeFilterFile>${log4jParentDir}/findbugs-exclude-filter.xml</excludeFilterFile>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jxr-plugin</artifactId>
- <version>${jxr.plugin.version}</version>
- <reportSets>
- <reportSet>
- <id>non-aggregate</id>
- <reports>
- <report>jxr</report>
- </reports>
- </reportSet>
- <reportSet>
- <id>aggregate</id>
- <reports>
- <report>aggregate</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-pmd-plugin</artifactId>
- <version>${pmd.plugin.version}</version>
- <configuration>
- <targetJdk>${maven.compiler.target}</targetJdk>
- </configuration>
- </plugin>
- </plugins>
- </reporting>
-</project>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbConnection.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbConnection.java b/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbConnection.java
deleted file mode 100644
index c3f6eaa..0000000
--- a/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbConnection.java
+++ /dev/null
@@ -1,103 +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.mongodb;
-
-import org.apache.logging.log4j.Level;
-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.BSON;
-import org.bson.Transformer;
-
-import com.mongodb.BasicDBObject;
-import com.mongodb.DB;
-import com.mongodb.DBCollection;
-import com.mongodb.Mongo;
-import com.mongodb.MongoException;
-import com.mongodb.WriteConcern;
-
-/**
- * The MongoDB implementation of {@link NoSqlConnection}.
- */
-public final class MongoDbConnection extends AbstractNoSqlConnection<BasicDBObject, MongoDbObject> {
-
- private static final Logger LOGGER = StatusLogger.getLogger();
-
- static {
- BSON.addEncodingHook(Level.class, new Transformer() {
- @Override
- public Object transform(final Object o) {
- if (o instanceof Level) {
- return ((Level) o).name();
- }
- return o;
- }
- });
- }
-
- private final DBCollection collection;
- private final WriteConcern writeConcern;
-
- public MongoDbConnection(final DB database, final WriteConcern writeConcern, final String collectionName,
- final Boolean isCapped, final Integer collectionSize) {
- if (database.collectionExists(collectionName)) {
- LOGGER.debug("Gettting collection {}", collectionName);
- collection = database.getCollection(collectionName);
- } else {
- final BasicDBObject options = new BasicDBObject();
- options.put("capped", isCapped);
- options.put("size", collectionSize);
- LOGGER.debug("Creating collection {} (capped = {}, size = {})", collectionName, isCapped, collectionSize);
- this.collection = database.createCollection(collectionName, options);
- }
- this.writeConcern = writeConcern;
- }
-
- @Override
- public MongoDbObject createObject() {
- return new MongoDbObject();
- }
-
- @Override
- public MongoDbObject[] createList(final int length) {
- return new MongoDbObject[length];
- }
-
- @Override
- public void insertObject(final NoSqlObject<BasicDBObject> object) {
- try {
- BasicDBObject unwrapped = object.unwrap();
- LOGGER.debug("Inserting object {}", unwrapped);
- this.collection.insert(unwrapped, this.writeConcern);
- } catch (final MongoException e) {
- throw new AppenderLoggingException("Failed to write log event to MongoDB due to error: " + e.getMessage(),
- e);
- }
- }
-
- @Override
- public void closeImpl() {
- // LOG4J2-1196
- Mongo mongo = this.collection.getDB().getMongo();
- LOGGER.debug("Closing {} client {}", mongo.getClass().getSimpleName(), mongo);
- mongo.close();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbObject.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbObject.java b/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbObject.java
deleted file mode 100644
index 541d941..0000000
--- a/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbObject.java
+++ /dev/null
@@ -1,66 +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.mongodb;
-
-import java.util.Collections;
-
-import org.apache.logging.log4j.core.appender.nosql.NoSqlObject;
-
-import com.mongodb.BasicDBList;
-import com.mongodb.BasicDBObject;
-
-/**
- * The MongoDB implementation of {@link NoSqlObject}.
- */
-public final class MongoDbObject implements NoSqlObject<BasicDBObject> {
- private final BasicDBObject mongoObject;
-
- public MongoDbObject() {
- this.mongoObject = new BasicDBObject();
- }
-
- @Override
- public void set(final String field, final Object value) {
- this.mongoObject.append(field, value);
- }
-
- @Override
- public void set(final String field, final NoSqlObject<BasicDBObject> value) {
- this.mongoObject.append(field, value.unwrap());
- }
-
- @Override
- public void set(final String field, final Object[] values) {
- final BasicDBList list = new BasicDBList();
- Collections.addAll(list, values);
- this.mongoObject.append(field, list);
- }
-
- @Override
- public void set(final String field, final NoSqlObject<BasicDBObject>[] values) {
- final BasicDBList list = new BasicDBList();
- for (final NoSqlObject<BasicDBObject> value : values) {
- list.add(value.unwrap());
- }
- this.mongoObject.append(field, list);
- }
-
- @Override
- public BasicDBObject unwrap() {
- return this.mongoObject;
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbProvider.java
----------------------------------------------------------------------
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
deleted file mode 100644
index bcc0420..0000000
--- a/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbProvider.java
+++ /dev/null
@@ -1,351 +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.mongodb;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.Core;
-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.PluginFactory;
-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.core.util.NameUtil;
-import org.apache.logging.log4j.core.appender.nosql.NoSqlProvider;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.util.LoaderUtil;
-import org.apache.logging.log4j.util.Strings;
-
-import com.mongodb.DB;
-import com.mongodb.MongoClient;
-import com.mongodb.MongoCredential;
-import com.mongodb.ServerAddress;
-import com.mongodb.WriteConcern;
-
-/**
- * The MongoDB implementation of {@link NoSqlProvider}.
- */
-@Plugin(name = "MongoDb", category = Core.CATEGORY_NAME, printObject = true)
-public final class MongoDbProvider implements NoSqlProvider<MongoDbConnection> {
-
- private static final WriteConcern DEFAULT_WRITE_CONCERN = WriteConcern.ACKNOWLEDGED;
- private static final Logger LOGGER = StatusLogger.getLogger();
- private static final int DEFAULT_PORT = 27017;
- private static final int DEFAULT_COLLECTION_SIZE = 536870912;
-
- private final String collectionName;
- private final DB database;
- private final String description;
- private final WriteConcern writeConcern;
- private final boolean isCapped;
- private final Integer collectionSize;
-
- private MongoDbProvider(final DB database, final WriteConcern writeConcern, final String collectionName,
- final boolean isCapped, final Integer collectionSize, final String description) {
- this.database = database;
- this.writeConcern = writeConcern;
- this.collectionName = collectionName;
- this.isCapped = isCapped;
- this.collectionSize = collectionSize;
- this.description = "mongoDb{ " + description + " }";
- }
-
- @Override
- public MongoDbConnection getConnection() {
- return new MongoDbConnection(this.database, this.writeConcern, this.collectionName, this.isCapped, this.collectionSize);
- }
-
- @Override
- public String toString() {
- return this.description;
- }
-
- /**
- * Factory method for creating a MongoDB provider within the plugin manager.
- *
- * @param collectionName The name of the MongoDB collection to which log events should be written.
- * @param writeConcernConstant The {@link WriteConcern} constant to control writing details, defaults to
- * {@link WriteConcern#ACKNOWLEDGED}.
- * @param writeConcernConstantClassName The name of a class containing the aforementioned static WriteConcern
- * constant. Defaults to {@link WriteConcern}.
- * @param databaseName The name of the MongoDB database containing the collection to which log events should be
- * written. Mutually exclusive with {@code factoryClassName&factoryMethodName!=null}.
- * @param server The host name of the MongoDB server, defaults to localhost and mutually exclusive with
- * {@code factoryClassName&factoryMethodName!=null}.
- * @param port The port the MongoDB server is listening on, defaults to the default MongoDB port and mutually
- * exclusive with {@code factoryClassName&factoryMethodName!=null}.
- * @param userName The username to authenticate against the MongoDB server with.
- * @param password The password to authenticate against the MongoDB server with.
- * @param factoryClassName A fully qualified class name containing a static factory method capable of returning a
- * {@link DB} or a {@link MongoClient}.
- * @param factoryMethodName The name of the public static factory method belonging to the aforementioned factory
- * class.
- * @return a new MongoDB provider.
- * @deprecated in 2.8; use {@link #newBuilder()} instead.
- */
- @Deprecated
- public static MongoDbProvider createNoSqlProvider(
- final String collectionName,
- final String writeConcernConstant,
- final String writeConcernConstantClassName,
- final String databaseName,
- final String server,
- final String port,
- final String userName,
- final String password,
- final String factoryClassName,
- final String factoryMethodName) {
- LOGGER.info("createNoSqlProvider");
- return newBuilder().setCollectionName(collectionName).setWriteConcernConstant(writeConcernConstantClassName)
- .setWriteConcernConstant(writeConcernConstant).setDatabaseName(databaseName).setServer(server)
- .setPort(port).setUserName(userName).setPassword(password).setFactoryClassName(factoryClassName)
- .setFactoryMethodName(factoryMethodName).build();
- }
-
- @PluginBuilderFactory
- public static <B extends Builder<B>> B newBuilder() {
- return new Builder<B>().asBuilder();
- }
-
- public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B>
- implements org.apache.logging.log4j.core.util.Builder<MongoDbProvider> {
-
- @PluginBuilderAttribute
- @ValidHost
- private String server = "localhost";
-
- @PluginBuilderAttribute
- @ValidPort
- private String port = "" + DEFAULT_PORT;
-
- @PluginBuilderAttribute
- @Required(message = "No database name provided")
- private String databaseName;
-
- @PluginBuilderAttribute
- @Required(message = "No collection name provided")
- private String collectionName;
-
- @PluginBuilderAttribute
- private String userName;
-
- @PluginBuilderAttribute(sensitive = true)
- private String password;
-
- @PluginBuilderAttribute("capped")
- private boolean isCapped = false;
-
- @PluginBuilderAttribute
- private int collectionSize = DEFAULT_COLLECTION_SIZE;
-
- @PluginBuilderAttribute
- private String factoryClassName;
-
- @PluginBuilderAttribute
- private String factoryMethodName;
-
- @PluginBuilderAttribute
- private String writeConcernConstantClassName;
-
- @PluginBuilderAttribute
- private String writeConcernConstant;
-
- public B setServer(final String server) {
- this.server = server;
- return asBuilder();
- }
-
- public B setPort(final String port) {
- this.port = port;
- return asBuilder();
- }
-
- public B setDatabaseName(final String databaseName) {
- this.databaseName = databaseName;
- return asBuilder();
- }
-
- public B setCollectionName(final String collectionName) {
- this.collectionName = collectionName;
- return asBuilder();
- }
-
- public B setUserName(final String userName) {
- this.userName = userName;
- return asBuilder();
- }
-
- public B setPassword(final String password) {
- this.password = password;
- return asBuilder();
- }
-
- public B setCapped(final boolean isCapped) {
- this.isCapped = isCapped;
- return asBuilder();
- }
-
- public B setCollectionSize(final int collectionSize) {
- this.collectionSize = collectionSize;
- 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 setWriteConcernConstantClassName(final String writeConcernConstantClassName) {
- this.writeConcernConstantClassName = writeConcernConstantClassName;
- return asBuilder();
- }
-
- public B setWriteConcernConstant(final String writeConcernConstant) {
- this.writeConcernConstant = writeConcernConstant;
- return asBuilder();
- }
-
- @Override
- public MongoDbProvider build() {
- DB database;
- String description;
- 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 DB) {
- database = (DB) object;
- } else if (object instanceof MongoClient) {
- if (Strings.isNotEmpty(databaseName)) {
- database = ((MongoClient) object).getDB(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);
- return null;
- } else {
- LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}].", factoryClassName,
- factoryMethodName, object.getClass().getName());
- return null;
- }
-
- description = "database=" + database.getName();
- final List<ServerAddress> addresses = database.getMongo().getAllAddress();
- if (addresses.size() == 1) {
- description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort();
- } else {
- description += ", servers=[";
- for (final ServerAddress address : addresses) {
- description += " { " + address.getHost() + ", " + address.getPort() + " } ";
- }
- description += "]";
- }
- } 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)) {
- final List<MongoCredential> credentials = new ArrayList<>();
- description = "database=" + databaseName;
- if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) {
- description += ", username=" + userName + ", passwordHash="
- + NameUtil.md5(password + MongoDbProvider.class.getName());
- credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray()));
- }
- try {
- final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT);
- description += ", server=" + server + ", port=" + portInt;
- database = new MongoClient(new ServerAddress(server, portInt), credentials).getDB(databaseName);
- } catch (final Exception e) {
- LOGGER.error(
- "Failed to obtain a database instance from the MongoClient at server [{}] and " + "port [{}].",
- server, port);
- return null;
- }
- } else {
- LOGGER.error("No factory method was provided so the database name is required.");
- return null;
- }
-
- try {
- database.getCollectionNames(); // 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);
- return null;
- }
-
- final WriteConcern writeConcern = toWriteConcern(writeConcernConstant, writeConcernConstantClassName);
-
- return new MongoDbProvider(database, writeConcern, collectionName, isCapped, collectionSize, description);
- }
-
- 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;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/package-info.java
----------------------------------------------------------------------
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
deleted file mode 100644
index f944511..0000000
--- a/log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/package-info.java
+++ /dev/null
@@ -1,20 +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.
- */
-package org.apache.logging.log4j.mongodb;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/site/markdown/index.md.vm
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/site/markdown/index.md.vm b/log4j-mongodb/src/site/markdown/index.md.vm
deleted file mode 100644
index 0d1eb7a..0000000
--- a/log4j-mongodb/src/site/markdown/index.md.vm
+++ /dev/null
@@ -1,48 +0,0 @@
-<!-- vim: set syn=markdown : -->
-<!--
- 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.
--->
-#set($h1='#')
-#set($h2='##')
-## TODO: use properties for dynamic dependency versions
-
-$h1 MongoDB appender
-
-[MongoDB](http://www.mongodb.org/) is supported through the
-[Java MongoDB Driver](http://docs.mongodb.org/ecosystem/drivers/java/).
-
-```
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>mongo-java-driver</artifactId>
- <version>2.14.3</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>mongo-java-driver</artifactId>
- </dependency>
- </dependencies>
-```
-
-$h2 Requirements
-
-The MongoDB Appender is dependent on the Log4j 2 API and implementation.
-For more information, see [Runtime Dependencies](../runtime-dependencies.html).
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/site/site.xml
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/site/site.xml b/log4j-mongodb/src/site/site.xml
deleted file mode 100644
index f5db26e..0000000
--- a/log4j-mongodb/src/site/site.xml
+++ /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.
-
--->
-<project name="Log4j MongoDB 2.x Appender"
- xmlns="http://maven.apache.org/DECORATION/1.4.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/DECORATION/1.4.0 http://maven.apache.org/xsd/decoration-1.4.0.xsd">
- <body>
- <links>
- <item name="Apache" href="http://www.apache.org/" />
- <item name="Logging Services" href="http://logging.apache.org/"/>
- <item name="Log4j" href="../index.html"/>
- </links>
-
- <!-- Component-specific reports -->
- <menu ref="reports"/>
-
- <!-- Overall Project Info -->
- <menu name="Log4j Project Information" img="icon-info-sign">
- <item name="Dependencies" href="../dependencies.html" />
- <item name="Dependency Convergence" href="../dependency-convergence.html" />
- <item name="Dependency Management" href="../dependency-management.html" />
- <item name="Project Team" href="../team-list.html" />
- <item name="Mailing Lists" href="../mail-lists.html" />
- <item name="Issue Tracking" href="../issue-tracking.html" />
- <item name="Project License" href="../license.html" />
- <item name="Source Repository" href="../source-repository.html" />
- <item name="Project Summary" href="../project-summary.html" />
- </menu>
-
- <menu name="Log4j Project Reports" img="icon-cog">
- <item name="Changes Report" href="../changes-report.html" />
- <item name="JIRA Report" href="../jira-report.html" />
- <item name="Surefire Report" href="../surefire-report.html" />
- <item name="RAT Report" href="../rat-report.html" />
- </menu>
- </body>
-</project>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/Java8Test.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/Java8Test.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/Java8Test.java
deleted file mode 100644
index 32b9a72..0000000
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/Java8Test.java
+++ /dev/null
@@ -1,48 +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.mongodb;
-
-import org.apache.commons.lang3.JavaVersion;
-import org.apache.commons.lang3.SystemUtils;
-import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Runs all MongoDB only on Java 8.
- * <p>
- * The test framework {@code de.flapdoodle.embed.mongo} requires Java 8.
- * </p>
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({ MongoDbTestTestRuleTestJava8.class, MongoDbAuthFailureTestJava8.class, MongoDbCappedTestJava8.class,
- MongoDbMapMessageTestJava8.class, MongoDbTestJava8.class })
-public class Java8Test {
-
- @BeforeClass
- public static void beforeClass() {
- Assume.assumeTrue(SystemUtils.JAVA_VERSION, SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8));
- }
-
- @Test
- public void test() {
- // noop
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTestJava8.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTestJava8.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTestJava8.java
deleted file mode 100644
index 42e5031..0000000
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbAuthFailureTestJava8.java
+++ /dev/null
@@ -1,68 +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.mongodb;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.categories.Appenders;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.apache.logging.log4j.test.AvailablePortSystemPropertyTestRule;
-import org.apache.logging.log4j.test.RuleChainFactory;
-import org.bson.Document;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.RuleChain;
-
-import com.mongodb.MongoClient;
-import com.mongodb.client.MongoCollection;
-import com.mongodb.client.MongoDatabase;
-
-/**
- * This class name does NOT end in "Test" in order to only be picked up by {@link Java8Test}.
- *
- * TODO set up the log4j user in MongoDB.
- */
-@Category(Appenders.MongoDb.class)
-public class MongoDbAuthFailureTestJava8 {
-
- private static LoggerContextRule loggerContextTestRule = new LoggerContextRule("log4j2-mongodb-auth-failure.xml");
-
- private static final AvailablePortSystemPropertyTestRule mongoDbPortTestRule = AvailablePortSystemPropertyTestRule
- .create(TestConstants.SYS_PROP_NAME_PORT);
-
- private static final MongoDbTestRule mongoDbTestRule = new MongoDbTestRule(mongoDbPortTestRule.getName());
-
- @ClassRule
- public static RuleChain ruleChain = RuleChainFactory.create(mongoDbPortTestRule, mongoDbTestRule,
- loggerContextTestRule);
-
- @Test
- public void test() {
- final Logger logger = LogManager.getLogger();
- logger.info("Hello log");
- try (final MongoClient mongoClient = mongoDbTestRule.getMongoClient()) {
- final MongoDatabase database = mongoClient.getDatabase("test");
- Assert.assertNotNull(database);
- final MongoCollection<Document> collection = database.getCollection("applog");
- Assert.assertNotNull(collection);
- Document first = collection.find().first();
- Assert.assertNull(first);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedTestJava8.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedTestJava8.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedTestJava8.java
deleted file mode 100644
index 2b48e43..0000000
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCappedTestJava8.java
+++ /dev/null
@@ -1,67 +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.mongodb;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.categories.Appenders;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.apache.logging.log4j.test.AvailablePortSystemPropertyTestRule;
-import org.apache.logging.log4j.test.RuleChainFactory;
-import org.bson.Document;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.RuleChain;
-
-import com.mongodb.MongoClient;
-import com.mongodb.client.MongoCollection;
-import com.mongodb.client.MongoDatabase;
-
-/**
- * This class name does NOT end in "Test" in order to only be picked up by {@link Java8Test}.
- */
-@Category(Appenders.MongoDb.class)
-public class MongoDbCappedTestJava8 {
-
- private static LoggerContextRule loggerContextTestRule = new LoggerContextRule("log4j2-mongodb-capped.xml");
-
- private static final AvailablePortSystemPropertyTestRule mongoDbPortTestRule = AvailablePortSystemPropertyTestRule
- .create(TestConstants.SYS_PROP_NAME_PORT);
-
- private static final MongoDbTestRule mongoDbTestRule = new MongoDbTestRule(mongoDbPortTestRule.getName());
-
- @ClassRule
- public static RuleChain ruleChain = RuleChainFactory.create(mongoDbPortTestRule, mongoDbTestRule,
- loggerContextTestRule);
-
- @Test
- public void test() {
- final Logger logger = LogManager.getLogger();
- logger.info("Hello log");
- try (final MongoClient mongoClient = mongoDbTestRule.getMongoClient()) {
- final MongoDatabase database = mongoClient.getDatabase("test");
- Assert.assertNotNull(database);
- final MongoCollection<Document> collection = database.getCollection("applog");
- Assert.assertNotNull(collection);
- Document first = collection.find().first();
- Assert.assertNotNull(first);
- Assert.assertEquals(first.toJson(), "Hello log", first.getString("message"));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTestJava8.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTestJava8.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTestJava8.java
deleted file mode 100644
index b066222..0000000
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbMapMessageTestJava8.java
+++ /dev/null
@@ -1,73 +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.mongodb;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.categories.Appenders;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.apache.logging.log4j.message.MapMessage;
-import org.apache.logging.log4j.test.AvailablePortSystemPropertyTestRule;
-import org.apache.logging.log4j.test.RuleChainFactory;
-import org.bson.Document;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.RuleChain;
-
-import com.mongodb.MongoClient;
-import com.mongodb.client.MongoCollection;
-import com.mongodb.client.MongoDatabase;
-
-/**
- * This class name does NOT end in "Test" in order to only be picked up by {@link Java8Test}.
- */
-@Category(Appenders.MongoDb.class)
-public class MongoDbMapMessageTestJava8 {
-
- private static LoggerContextRule loggerContextTestRule = new LoggerContextRule("log4j2-mongodb-map-message.xml");
-
- private static final AvailablePortSystemPropertyTestRule mongoDbPortTestRule = AvailablePortSystemPropertyTestRule
- .create(TestConstants.SYS_PROP_NAME_PORT);
-
- private static final MongoDbTestRule mongoDbTestRule = new MongoDbTestRule(mongoDbPortTestRule.getName());
-
- @ClassRule
- public static RuleChain ruleChain = RuleChainFactory.create(mongoDbPortTestRule, mongoDbTestRule,
- loggerContextTestRule);
-
- @Test
- public void test() {
- final Logger logger = LogManager.getLogger();
- final MapMessage mapMessage = new MapMessage();
- mapMessage.with("SomeName", "SomeValue");
- mapMessage.with("SomeInt", 1);
- logger.info(mapMessage);
- //
- try (final MongoClient mongoClient = mongoDbTestRule.getMongoClient()) {
- final MongoDatabase database = mongoClient.getDatabase("test");
- Assert.assertNotNull(database);
- final MongoCollection<Document> collection = database.getCollection("applog");
- Assert.assertNotNull(collection);
- Document first = collection.find().first();
- Assert.assertNotNull(first);
- Assert.assertEquals(first.toJson(), "SomeValue", first.getString("SomeName"));
- Assert.assertEquals(first.toJson(), Integer.valueOf(1), first.getInteger("SomeInt"));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestJava8.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestJava8.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestJava8.java
deleted file mode 100644
index d3fa141..0000000
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestJava8.java
+++ /dev/null
@@ -1,67 +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.mongodb;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.categories.Appenders;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.apache.logging.log4j.test.AvailablePortSystemPropertyTestRule;
-import org.apache.logging.log4j.test.RuleChainFactory;
-import org.bson.Document;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.RuleChain;
-
-import com.mongodb.MongoClient;
-import com.mongodb.client.MongoCollection;
-import com.mongodb.client.MongoDatabase;
-
-/**
- * This class name does NOT end in "Test" in order to only be picked up by {@link Java8Test}.
- */
-@Category(Appenders.MongoDb.class)
-public class MongoDbTestJava8 {
-
- private static LoggerContextRule loggerContextTestRule = new LoggerContextRule("log4j2-mongodb.xml");
-
- private static final AvailablePortSystemPropertyTestRule mongoDbPortTestRule = AvailablePortSystemPropertyTestRule
- .create(TestConstants.SYS_PROP_NAME_PORT);
-
- private static final MongoDbTestRule mongoDbTestRule = new MongoDbTestRule(mongoDbPortTestRule.getName());
-
- @ClassRule
- public static RuleChain ruleChain = RuleChainFactory.create(mongoDbPortTestRule, mongoDbTestRule,
- loggerContextTestRule);
-
- @Test
- public void test() {
- final Logger logger = LogManager.getLogger();
- logger.info("Hello log");
- try (final MongoClient mongoClient = mongoDbTestRule.getMongoClient()) {
- final MongoDatabase database = mongoClient.getDatabase("test");
- Assert.assertNotNull(database);
- final MongoCollection<Document> collection = database.getCollection("applog");
- Assert.assertNotNull(collection);
- Document first = collection.find().first();
- Assert.assertNotNull(first);
- Assert.assertEquals(first.toJson(), "Hello log", first.getString("message"));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestRule.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestRule.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestRule.java
deleted file mode 100644
index 73fef40..0000000
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestRule.java
+++ /dev/null
@@ -1,139 +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.mongodb;
-
-import java.util.Objects;
-
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-import com.mongodb.MongoClient;
-
-import de.flapdoodle.embed.mongo.MongodExecutable;
-import de.flapdoodle.embed.mongo.MongodProcess;
-import de.flapdoodle.embed.mongo.MongodStarter;
-import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
-import de.flapdoodle.embed.mongo.config.Net;
-import de.flapdoodle.embed.mongo.config.Timeout;
-import de.flapdoodle.embed.mongo.distribution.Version;
-import de.flapdoodle.embed.process.runtime.Network;
-
-/**
- * A JUnit test rule to manage a MongoDB embedded instance.
- */
-public class MongoDbTestRule implements TestRule {
-
- private static final int BUILDER_TIMEOUT_MILLIS = 30000;
-
- /**
- * Store {@link MongodStarter} (or RuntimeConfig) in a static final field if you want to use artifact store caching
- * (or else disable caching).
- * <p>
- * The test framework {@code de.flapdoodle.embed.mongo} requires Java 8.
- * </p>
- */
- protected static final MongodStarter starter = MongodStarter.getDefaultInstance();
-
- public static int getBuilderTimeoutMillis() {
- return BUILDER_TIMEOUT_MILLIS;
- }
-
- public static MongodStarter getStarter() {
- return starter;
- }
-
- protected final String portSystemPropertyName;
- protected MongoClient mongoClient;
- protected MongodExecutable mongodExecutable;
- protected MongodProcess mongodProcess;
-
- /**
- * Constructs a new test rule.
- *
- * @param portSystemPropertyName
- * The system property name for the MongoDB port.
- */
- public MongoDbTestRule(final String portSystemPropertyName) {
- this.portSystemPropertyName = Objects.requireNonNull(portSystemPropertyName, "portSystemPropertyName");
- }
-
- @Override
- public Statement apply(final Statement base, final Description description) {
- return new Statement() {
-
- @Override
- public void evaluate() throws Throwable {
- final String value = Objects.requireNonNull(System.getProperty(portSystemPropertyName),
- "System property '" + portSystemPropertyName + "' is null");
- final int port = Integer.parseInt(value);
- mongodExecutable = starter.prepare(
- // @formatter:off
- new MongodConfigBuilder()
- .version(Version.Main.PRODUCTION)
- .timeout(new Timeout(BUILDER_TIMEOUT_MILLIS))
- .net(
- new Net("localhost", port, Network.localhostIsIPv6()))
- .build());
- // @formatter:on
- mongodProcess = mongodExecutable.start();
- mongoClient = new MongoClient("localhost", port);
- try {
- base.evaluate();
- } finally {
- if (mongodProcess != null) {
- mongodProcess.stop();
- mongodProcess = null;
- }
- if (mongodExecutable != null) {
- mongodExecutable.stop();
- mongodExecutable = null;
- }
- }
- }
- };
- }
-
- public MongoClient getMongoClient() {
- return mongoClient;
- }
-
- public MongodExecutable getMongodExecutable() {
- return mongodExecutable;
- }
-
- public MongodProcess getMongodProcess() {
- return mongodProcess;
- }
-
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("MongoDbTestRule [portSystemPropertyName=");
- builder.append(portSystemPropertyName);
- builder.append(", mongoClient=");
- builder.append(mongoClient);
- builder.append(", mongodExecutable=");
- builder.append(mongodExecutable);
- builder.append(", mongodProcess=");
- builder.append(mongodProcess);
- builder.append("]");
- return builder.toString();
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestTestRuleTestJava8.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestTestRuleTestJava8.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestTestRuleTestJava8.java
deleted file mode 100644
index f0a3377..0000000
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbTestTestRuleTestJava8.java
+++ /dev/null
@@ -1,69 +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.mongodb;
-
-import org.apache.commons.lang3.JavaVersion;
-import org.apache.commons.lang3.SystemUtils;
-import org.apache.logging.log4j.test.AvailablePortSystemPropertyTestRule;
-import org.apache.logging.log4j.test.RuleChainFactory;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.rules.RuleChain;
-
-import com.mongodb.client.MongoIterable;
-
-/**
- * Tests MongoDbRule. This class name does NOT end in "Test" in order to only be picked up by {@link Java8Test}.
- * <p>
- * The test framework {@code de.flapdoodle.embed.mongo} requires Java 8.
- * </p>
- */
-public class MongoDbTestTestRuleTestJava8 {
-
- @BeforeClass
- public static void beforeClass() {
- Assume.assumeTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8));
- }
-
- private static final AvailablePortSystemPropertyTestRule mongoDbPortTestRule = AvailablePortSystemPropertyTestRule
- .create(TestConstants.SYS_PROP_NAME_PORT);
-
- private static final MongoDbTestRule mongoDbTestRule = new MongoDbTestRule(mongoDbPortTestRule.getName());
-
- @ClassRule
- public static RuleChain mongoDbChain = RuleChainFactory.create(mongoDbPortTestRule, mongoDbTestRule);
-
- @Test
- public void testAccess() {
- final MongoIterable<String> databaseNames = mongoDbTestRule.getMongoClient().listDatabaseNames();
- Assert.assertNotNull(databaseNames);
- Assert.assertNotNull(databaseNames.first());
- }
-
- @Test
- public void testMongoDbTestRule() {
- Assert.assertNotNull(MongoDbTestRule.getStarter());
- Assert.assertNotNull(mongoDbTestRule);
- Assert.assertNotNull(mongoDbTestRule.getMongoClient());
- Assert.assertNotNull(mongoDbTestRule.getMongodExecutable());
- Assert.assertNotNull(mongoDbTestRule.getMongodProcess());
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/TestConstants.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/TestConstants.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/TestConstants.java
deleted file mode 100644
index c22fa98..0000000
--- a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/TestConstants.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.mongodb;
-
-public class TestConstants {
-
- public static final String SYS_PROP_NAME_PORT = "MongoDBTestPort";
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/test/resources/log4j2-mongodb-auth-failure.xml
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb-auth-failure.xml b/log4j-mongodb/src/test/resources/log4j2-mongodb-auth-failure.xml
deleted file mode 100644
index 548a8e8..0000000
--- a/log4j-mongodb/src/test/resources/log4j2-mongodb-auth-failure.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
-
--->
-<Configuration status="error">
- <Appenders>
- <NoSql name="MongoDbAppender">
- <MongoDb databaseName="test" collectionName="applog" server="localhost" userName="log4jUser" password="12345678"
- port="${sys:MongoDBTestPort:-27017}" />
- </NoSql>
- </Appenders>
- <Loggers>
- <Root level="ALL">
- <AppenderRef ref="MongoDbAppender" />
- </Root>
- </Loggers>
-</Configuration>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/test/resources/log4j2-mongodb-capped.xml
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb-capped.xml b/log4j-mongodb/src/test/resources/log4j2-mongodb-capped.xml
deleted file mode 100644
index 330f958..0000000
--- a/log4j-mongodb/src/test/resources/log4j2-mongodb-capped.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
-
--->
-<Configuration status="error">
- <Appenders>
- <NoSql name="MongoDbAppender">
- <MongoDb databaseName="test" collectionName="applog" server="localhost" capped="true" collectionSize="1073741824"
- port="${sys:MongoDBTestPort:-27017}" />
- </NoSql>
- </Appenders>
- <Loggers>
- <Root level="ALL">
- <AppenderRef ref="MongoDbAppender" />
- </Root>
- </Loggers>
-</Configuration>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/test/resources/log4j2-mongodb-map-message.xml
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb-map-message.xml b/log4j-mongodb/src/test/resources/log4j2-mongodb-map-message.xml
deleted file mode 100644
index 82fa09a..0000000
--- a/log4j-mongodb/src/test/resources/log4j2-mongodb-map-message.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
-
--->
-<Configuration status="debug">
- <Appenders>
- <NoSql name="MongoDbAppender">
- <MongoDb databaseName="test" collectionName="applog" server="localhost"
- port="${sys:MongoDBTestPort:-27017}" />
- <MessageLayout />
- </NoSql>
- </Appenders>
- <Loggers>
- <Root level="ALL">
- <AppenderRef ref="MongoDbAppender" />
- </Root>
- </Loggers>
-</Configuration>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb/src/test/resources/log4j2-mongodb.xml
----------------------------------------------------------------------
diff --git a/log4j-mongodb/src/test/resources/log4j2-mongodb.xml b/log4j-mongodb/src/test/resources/log4j2-mongodb.xml
deleted file mode 100644
index b132842..0000000
--- a/log4j-mongodb/src/test/resources/log4j2-mongodb.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
-
--->
-<Configuration status="error">
- <Appenders>
- <NoSql name="MongoDbAppender">
- <MongoDb databaseName="test" collectionName="applog" server="localhost"
- port="${sys:MongoDBTestPort:-27017}" />
- </NoSql>
- </Appenders>
- <Loggers>
- <Root level="ALL">
- <AppenderRef ref="MongoDbAppender" />
- </Root>
- </Loggers>
-</Configuration>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/pom.xml b/log4j-mongodb2/pom.xml
new file mode 100644
index 0000000..1403350
--- /dev/null
+++ b/log4j-mongodb2/pom.xml
@@ -0,0 +1,189 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<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">
+ <parent>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>2.10.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>log4j-mongodb2</artifactId>
+ <name>Apache Log4j MongoDB 2</name>
+ <description>
+ MongoDB appender for Log4j using the MongoDB 2 driver API.
+ </description>
+ <properties>
+ <log4jParentDir>${basedir}/..</log4jParentDir>
+ <docLabel>MongoDB 2 Documentation</docLabel>
+ <projectDir>/log4j-mongodb2</projectDir>
+ <module.name>org.apache.logging.log4j.mongodb2</module.name>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mongodb</groupId>
+ <artifactId>mongo-java-driver</artifactId>
+ </dependency>
+ <!-- Test Dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>de.flapdoodle.embed</groupId>
+ <artifactId>de.flapdoodle.embed.mongo</artifactId>
+ <version>2.0.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Fragment-Host>org.apache.logging.log4j.core</Fragment-Host>
+ <Export-Package>*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-changes-plugin</artifactId>
+ <version>${changes.plugin.version}</version>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>changes-report</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ <configuration>
+ <issueLinkTemplate>%URL%/show_bug.cgi?id=%ISSUE%</issueLinkTemplate>
+ <useJql>true</useJql>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${checkstyle.plugin.version}</version>
+ <configuration>
+ <!--<propertiesLocation>${vfs.parent.dir}/checkstyle.properties</propertiesLocation> -->
+ <configLocation>${log4jParentDir}/checkstyle.xml</configLocation>
+ <suppressionsLocation>${log4jParentDir}/checkstyle-suppressions.xml</suppressionsLocation>
+ <enableRulesSummary>false</enableRulesSummary>
+ <propertyExpansion>basedir=${basedir}</propertyExpansion>
+ <propertyExpansion>licensedir=${log4jParentDir}/checkstyle-header.txt</propertyExpansion>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>${javadoc.plugin.version}</version>
+ <configuration>
+ <bottom><![CDATA[<p align="center">Copyright © {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.<br />
+ Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo,
+ and the Apache Log4j logo are trademarks of The Apache Software Foundation.</p>]]></bottom>
+ <!-- module link generation is completely broken in the javadoc plugin for a multi-module non-aggregating
+ project -->
+ <detectOfflineLinks>false</detectOfflineLinks>
+ <linksource>true</linksource>
+ </configuration>
+ <reportSets>
+ <reportSet>
+ <id>non-aggregate</id>
+ <reports>
+ <report>javadoc</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>${findbugs.plugin.version}</version>
+ <configuration>
+ <fork>true</fork>
+ <jvmArgs>-Duser.language=en</jvmArgs>
+ <threshold>Normal</threshold>
+ <effort>Default</effort>
+ <excludeFilterFile>${log4jParentDir}/findbugs-exclude-filter.xml</excludeFilterFile>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jxr-plugin</artifactId>
+ <version>${jxr.plugin.version}</version>
+ <reportSets>
+ <reportSet>
+ <id>non-aggregate</id>
+ <reports>
+ <report>jxr</report>
+ </reports>
+ </reportSet>
+ <reportSet>
+ <id>aggregate</id>
+ <reports>
+ <report>aggregate</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <version>${pmd.plugin.version}</version>
+ <configuration>
+ <targetJdk>${maven.compiler.target}</targetJdk>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27337afe/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/MongoDbConnection.java
----------------------------------------------------------------------
diff --git a/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/MongoDbConnection.java b/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/MongoDbConnection.java
new file mode 100644
index 0000000..ec3b7dd
--- /dev/null
+++ b/log4j-mongodb2/src/main/java/org/apache/logging/log4j/mongodb2/MongoDbConnection.java
@@ -0,0 +1,103 @@
+/*
+ * 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.mongodb2;
+
+import org.apache.logging.log4j.Level;
+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.BSON;
+import org.bson.Transformer;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.Mongo;
+import com.mongodb.MongoException;
+import com.mongodb.WriteConcern;
+
+/**
+ * The MongoDB implementation of {@link NoSqlConnection}.
+ */
+public final class MongoDbConnection extends AbstractNoSqlConnection<BasicDBObject, MongoDbObject> {
+
+ private static final Logger LOGGER = StatusLogger.getLogger();
+
+ static {
+ BSON.addEncodingHook(Level.class, new Transformer() {
+ @Override
+ public Object transform(final Object o) {
+ if (o instanceof Level) {
+ return ((Level) o).name();
+ }
+ return o;
+ }
+ });
+ }
+
+ private final DBCollection collection;
+ private final WriteConcern writeConcern;
+
+ public MongoDbConnection(final DB database, final WriteConcern writeConcern, final String collectionName,
+ final Boolean isCapped, final Integer collectionSize) {
+ if (database.collectionExists(collectionName)) {
+ LOGGER.debug("Gettting collection {}", collectionName);
+ collection = database.getCollection(collectionName);
+ } else {
+ final BasicDBObject options = new BasicDBObject();
+ options.put("capped", isCapped);
+ options.put("size", collectionSize);
+ LOGGER.debug("Creating collection {} (capped = {}, size = {})", collectionName, isCapped, collectionSize);
+ this.collection = database.createCollection(collectionName, options);
+ }
+ this.writeConcern = writeConcern;
+ }
+
+ @Override
+ public void closeImpl() {
+ // LOG4J2-1196
+ final Mongo mongo = this.collection.getDB().getMongo();
+ LOGGER.debug("Closing {} client {}", mongo.getClass().getSimpleName(), mongo);
+ mongo.close();
+ }
+
+ @Override
+ public MongoDbObject[] createList(final int length) {
+ return new MongoDbObject[length];
+ }
+
+ @Override
+ public MongoDbObject createObject() {
+ return new MongoDbObject();
+ }
+
+ @Override
+ public void insertObject(final NoSqlObject<BasicDBObject> object) {
+ try {
+ final BasicDBObject unwrapped = object.unwrap();
+ LOGGER.debug("Inserting object {}", unwrapped);
+ this.collection.insert(unwrapped, this.writeConcern);
+ } catch (final MongoException e) {
+ throw new AppenderLoggingException("Failed to write log event to MongoDB due to error: " + e.getMessage(),
+ e);
+ }
+ }
+
+}