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 2015/09/24 10:16:20 UTC
[2/2] logging-log4j2 git commit: [LOG4J2-1132] Do not use MongoDB
driver 2.13.3 deprecated methods.
[LOG4J2-1132] Do not use MongoDB driver 2.13.3 deprecated methods.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/ae78b2ef
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ae78b2ef
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ae78b2ef
Branch: refs/heads/master
Commit: ae78b2ef6b3ed82f73aa689425faee5876517bf6
Parents: 8ba0ee5
Author: ggregory <gg...@apache.org>
Authored: Thu Sep 24 01:16:16 2015 -0700
Committer: ggregory <gg...@apache.org>
Committed: Thu Sep 24 01:16:16 2015 -0700
----------------------------------------------------------------------
.../nosql/appender/AbstractNoSqlConnection.java | 48 ++++++
.../appender/couchdb/CouchDbConnection.java | 145 +++++++++----------
.../appender/mongodb/MongoDbConnection.java | 19 +--
.../log4j/nosql/appender/MongoDbTest.java | 4 +-
src/changes/changes.xml | 6 +
5 files changed, 131 insertions(+), 91 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ae78b2ef/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/AbstractNoSqlConnection.java
----------------------------------------------------------------------
diff --git a/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/AbstractNoSqlConnection.java b/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/AbstractNoSqlConnection.java
new file mode 100644
index 0000000..ac52eba
--- /dev/null
+++ b/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/AbstractNoSqlConnection.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.nosql.appender;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Facilitates implementations of {@link NoSqlConnection}.
+ *
+ * @param <W>
+ * See {@link NoSqlConnection}.
+ * @param <T>See
+ * {@link NoSqlConnection}.
+ */
+public abstract class AbstractNoSqlConnection<W, T extends NoSqlObject<W>> implements NoSqlConnection<W, T> {
+
+ private final AtomicBoolean closed = new AtomicBoolean(false);
+
+ @Override
+ public void close() {
+ if (this.closed.compareAndSet(false, true)) {
+ closeImpl();
+ }
+ }
+
+ protected abstract void closeImpl();
+
+ @Override
+ public boolean isClosed() {
+ return this.closed.get();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ae78b2ef/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/couchdb/CouchDbConnection.java
----------------------------------------------------------------------
diff --git a/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/couchdb/CouchDbConnection.java b/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/couchdb/CouchDbConnection.java
index dd77d38..2494a5c 100644
--- a/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/couchdb/CouchDbConnection.java
+++ b/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/couchdb/CouchDbConnection.java
@@ -1,76 +1,69 @@
-/*
- * 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.nosql.appender.couchdb;
-
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.apache.logging.log4j.core.appender.AppenderLoggingException;
-import org.apache.logging.log4j.nosql.appender.DefaultNoSqlObject;
-import org.apache.logging.log4j.nosql.appender.NoSqlConnection;
-import org.apache.logging.log4j.nosql.appender.NoSqlObject;
-import org.apache.logging.log4j.util.Strings;
-import org.lightcouch.CouchDbClient;
-import org.lightcouch.Response;
-
-/**
- * The Apache CouchDB implementation of {@link NoSqlConnection}.
- */
-public final class CouchDbConnection implements NoSqlConnection<Map<String, Object>, DefaultNoSqlObject> {
- private final CouchDbClient client;
- private final AtomicBoolean closed = new AtomicBoolean(false);
-
- public CouchDbConnection(final CouchDbClient client) {
- this.client = client;
- }
-
- @Override
- public DefaultNoSqlObject createObject() {
- return new DefaultNoSqlObject();
- }
-
- @Override
- public DefaultNoSqlObject[] createList(final int length) {
- return new DefaultNoSqlObject[length];
- }
-
- @Override
- public void insertObject(final NoSqlObject<Map<String, Object>> object) {
- try {
- final Response response = this.client.save(object.unwrap());
- if (Strings.isNotEmpty(response.getError())) {
- throw new AppenderLoggingException("Failed to write log event to CouchDB due to error: " +
- response.getError() + '.');
- }
- } catch (final Exception e) {
- throw new AppenderLoggingException("Failed to write log event to CouchDB due to error: " + e.getMessage(),
- e);
- }
- }
-
- @Override
- public void close() {
- if (this.closed.compareAndSet(false, true)) {
- this.client.shutdown();
- }
- }
-
- @Override
- public boolean isClosed() {
- return this.closed.get();
- }
-}
+/*
+ * 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.nosql.appender.couchdb;
+
+import java.util.Map;
+
+import org.apache.logging.log4j.core.appender.AppenderLoggingException;
+import org.apache.logging.log4j.nosql.appender.AbstractNoSqlConnection;
+import org.apache.logging.log4j.nosql.appender.DefaultNoSqlObject;
+import org.apache.logging.log4j.nosql.appender.NoSqlConnection;
+import org.apache.logging.log4j.nosql.appender.NoSqlObject;
+import org.apache.logging.log4j.util.Strings;
+import org.lightcouch.CouchDbClient;
+import org.lightcouch.Response;
+
+/**
+ * The Apache CouchDB implementation of {@link NoSqlConnection}.
+ */
+public final class CouchDbConnection extends AbstractNoSqlConnection<Map<String, Object>, DefaultNoSqlObject> {
+ private final CouchDbClient client;
+
+ public CouchDbConnection(final CouchDbClient client) {
+ this.client = client;
+ }
+
+ @Override
+ public DefaultNoSqlObject createObject() {
+ return new DefaultNoSqlObject();
+ }
+
+ @Override
+ public DefaultNoSqlObject[] createList(final int length) {
+ return new DefaultNoSqlObject[length];
+ }
+
+ @Override
+ public void insertObject(final NoSqlObject<Map<String, Object>> object) {
+ try {
+ final Response response = this.client.save(object.unwrap());
+ if (Strings.isNotEmpty(response.getError())) {
+ throw new AppenderLoggingException(
+ "Failed to write log event to CouchDB due to error: " + response.getError() + '.');
+ }
+ } catch (final Exception e) {
+ throw new AppenderLoggingException("Failed to write log event to CouchDB due to error: " + e.getMessage(),
+ e);
+ }
+ }
+
+ @Override
+ protected void closeImpl() {
+ this.client.shutdown();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ae78b2ef/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbConnection.java
----------------------------------------------------------------------
diff --git a/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbConnection.java b/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbConnection.java
index a803378..6b65fc3 100644
--- a/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbConnection.java
+++ b/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbConnection.java
@@ -19,6 +19,7 @@ package org.apache.logging.log4j.nosql.appender.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.nosql.appender.AbstractNoSqlConnection;
import org.apache.logging.log4j.nosql.appender.NoSqlConnection;
import org.apache.logging.log4j.nosql.appender.NoSqlObject;
import org.apache.logging.log4j.status.StatusLogger;
@@ -28,14 +29,13 @@ 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 implements NoSqlConnection<BasicDBObject, MongoDbObject> {
+public final class MongoDbConnection extends AbstractNoSqlConnection<BasicDBObject, MongoDbObject> {
private static final Logger LOGGER = StatusLogger.getLogger();
@@ -52,11 +52,9 @@ public final class MongoDbConnection implements NoSqlConnection<BasicDBObject, M
}
private final DBCollection collection;
- private final Mongo mongo;
private final WriteConcern writeConcern;
public MongoDbConnection(final DB database, final WriteConcern writeConcern, final String collectionName) {
- this.mongo = database.getMongo();
this.collection = database.getCollection(collectionName);
this.writeConcern = writeConcern;
}
@@ -82,15 +80,10 @@ public final class MongoDbConnection implements NoSqlConnection<BasicDBObject, M
}
@Override
- public void close() {
- // there's no need to call this.mongo.close() since that literally
- // closes the connection
- // MongoDBClient uses internal connection pooling
- // for more details, see LOG4J2-591
+ public void closeImpl() {
+ // there's no need to call this.mongo.close() since that literally closes the connection.
+ // MongoDBClient uses internal connection pooling.
+ // For more details, see LOG4J2-591.
}
- @Override
- public boolean isClosed() {
- return !this.mongo.getConnector().isOpen();
- }
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ae78b2ef/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/MongoDbTest.java
----------------------------------------------------------------------
diff --git a/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/MongoDbTest.java b/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/MongoDbTest.java
index 2513526..44d3d21 100644
--- a/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/MongoDbTest.java
+++ b/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/MongoDbTest.java
@@ -23,11 +23,11 @@ import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
-@Ignore("Requires a running MongoDB server")
+//@Ignore("Requires a running MongoDB server")
public class MongoDbTest {
@ClassRule
- public static LoggerContextRule context = new LoggerContextRule("log4j2-mongodb.xml");
+ public static LoggerContextRule context = new LoggerContextRule("log4j2-mongodb-auth.xml");
@Test
public void test() {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ae78b2ef/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ff8f590..146b4e2 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -30,6 +30,12 @@
<action issue="LOG4J2-1127" dev="ggregory" type="fix">
log4j2.xml cannot be parsed on Oracle Weblogic 12c
</action>
+ <action issue="LOG4J2-1132" dev="ggregory" type="fix">
+ Do not use MongoDB driver 2.13.3 deprecated methods.
+ </action>
+ <action issue="LOG4J2-1040" dev="ggregory" type="update">
+ Update MongoDB driver from 2.13.3 to 3.0.4.
+ </action>
<action issue="LOG4J2-1128" dev="ggregory" type="update">
Reuse StringBuilder to improve performance for String-based layouts: CSV, GELF, HTML, RFC524, Syslog.
</action>