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 2024/11/01 19:10:39 UTC
(logging-log4j2) branch 2.x updated: The MongoDb Appender shouldn't log a deprecation warning, GitHub issue #3151
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/2.x by this push:
new c662e6f415 The MongoDb Appender shouldn't log a deprecation warning, GitHub issue #3151
c662e6f415 is described below
commit c662e6f415ca378f2dfffde6bcd56ace488a4252
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Nov 1 15:10:33 2024 -0400
The MongoDb Appender shouldn't log a deprecation warning, GitHub
issue #3151
---
log4j-mongodb/pom.xml | 2 +
.../logging/log4j/mongodb/MongoDbProvider.java | 36 ++++++++++++-----
log4j-mongodb4/pom.xml | 2 +
.../logging/log4j/mongodb4/MongoDb4Provider.java | 47 ++++++++++++++++++++--
...51_fix_mongodb_appender_deprecation_warning.xml | 8 ++++
5 files changed, 82 insertions(+), 13 deletions(-)
diff --git a/log4j-mongodb/pom.xml b/log4j-mongodb/pom.xml
index b67845990f..8a71f4ff60 100644
--- a/log4j-mongodb/pom.xml
+++ b/log4j-mongodb/pom.xml
@@ -32,6 +32,8 @@
<!-- Dependency versions -->
<mongodb.version>5.2.0</mongodb.version>
<slf4j2.version>2.0.16</slf4j2.version>
+ <!-- Using bnd.baseline.skip for weird complaints; why are we running this at all for an appender impl? -->
+ <bnd.baseline.skip>true</bnd.baseline.skip>
</properties>
<dependencyManagement>
<dependencies>
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
index 0828b16648..69069949df 100644
--- 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
@@ -22,25 +22,43 @@ import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
import org.apache.logging.log4j.mongodb4.MongoDb4Connection;
import org.apache.logging.log4j.mongodb4.MongoDb4Provider;
-import org.apache.logging.log4j.mongodb4.MongoDb4Provider.Builder;
/**
* Delegates to {@link MongoDb4Provider} under the name {@code MongoDb}.
*/
/*
- * TODO: Currently the
- * {@link org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor}
- * assumes that the class generated by the plugin is the same as the annotated class.
- * To work around this we declare this class abstract and let it implement
- * {@link NoSqlProvider}.
+ * TODO: Currently the {@link org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor} assumes that the class generated by the plugin is the same
+ * as the annotated class. To work around this we declare this class abstract and let it implement {@link NoSqlProvider}.
*/
@Plugin(name = "MongoDb", category = Core.CATEGORY_NAME, printObject = true)
public abstract class MongoDbProvider implements NoSqlProvider<MongoDb4Connection> {
- private MongoDbProvider() {}
+ /**
+ * Builds new {@link MongoDb4Provider} instance.
+ */
+ public static class Builder extends MongoDb4Provider.Builder<Builder> {
+ @Override
+ public MongoDb4Provider build() {
+ // Don't issue MongoDb4Provider's WARN event.
+ return newMongoDb4Provider();
+ }
+ }
+
+ /**
+ * There are no instances.
+ */
+ private MongoDbProvider() {
+ // empty.
+ }
+
+ /**
+ * Creates a new builder.
+ *
+ * @return a new builder.
+ */
@PluginBuilderFactory
- public static <B extends Builder<B>> B newBuilder() {
- return MongoDb4Provider.newBuilder();
+ public static Builder newBuilder() {
+ return new Builder();
}
}
diff --git a/log4j-mongodb4/pom.xml b/log4j-mongodb4/pom.xml
index 960967c841..dac6c1f8ec 100644
--- a/log4j-mongodb4/pom.xml
+++ b/log4j-mongodb4/pom.xml
@@ -37,6 +37,8 @@
<!-- Dependency versions -->
<mongodb4.version>4.11.4</mongodb4.version>
<slf4j.version>2.0.16</slf4j.version>
+ <!-- Using bnd.baseline.skip for weird complaints; why are we running this at all for an appender impl? -->
+ <bnd.baseline.skip>true</bnd.baseline.skip>
</properties>
<dependencyManagement>
diff --git a/log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4Provider.java b/log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4Provider.java
index 299e369630..99e392237b 100644
--- a/log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4Provider.java
+++ b/log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4Provider.java
@@ -42,6 +42,11 @@ public final class MongoDb4Provider implements NoSqlProvider<MongoDb4Connection>
static final String PLUGIN_NAME = "MongoDb4";
+ /**
+ * Builds new {@link MongoDb4Provider} instance.
+ *
+ * @param <B> the builder type.
+ */
public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B>
implements org.apache.logging.log4j.core.util.Builder<MongoDb4Provider> {
@@ -58,26 +63,54 @@ public final class MongoDb4Provider implements NoSqlProvider<MongoDb4Connection>
@Override
public MongoDb4Provider build() {
StatusLogger.getLogger().warn("The {} Appender is deprecated, use the MongoDb Appender.", PLUGIN_NAME);
+ return newMongoDb4Provider();
+ }
+
+ protected MongoDb4Provider newMongoDb4Provider() {
return new MongoDb4Provider(connectionStringSource, capped, collectionSize);
}
+ /**
+ * Sets the MongoDB connection string.
+ *
+ * @param connectionStringSource the MongoDB connection string.
+ * @return this instance.
+ */
public B setConnectionStringSource(final String connectionStringSource) {
this.connectionStringSource = connectionStringSource;
return asBuilder();
}
+ /**
+ * Sets whether the MongoDB collection is capped.
+ *
+ * @param isCapped whether the MongoDB collection is capped.
+ * @return this instance.
+ */
public B setCapped(final boolean isCapped) {
this.capped = isCapped;
return asBuilder();
}
- public B setCollectionSize(final int collectionSize) {
- this.collectionSize = collectionSize;
+ /**
+ * Sets the maximum size in bytes of a capped collection.
+ *
+ * @param sizeInBytes the maximum size in bytes of a capped collection.
+ * @return this instance.
+ */
+ public B setCollectionSize(final int sizeInBytes) {
+ this.collectionSize = sizeInBytes;
return asBuilder();
}
- public B setCollectionSize(final long collectionSize) {
- this.collectionSize = collectionSize;
+ /**
+ * Sets the maximum size in bytes of a capped collection.
+ *
+ * @param sizeInBytes the maximum size in bytes of a capped collection.
+ * @return this instance.
+ */
+ public B setCollectionSize(final long sizeInBytes) {
+ this.collectionSize = sizeInBytes;
return asBuilder();
}
}
@@ -94,6 +127,12 @@ public final class MongoDb4Provider implements NoSqlProvider<MongoDb4Connection>
// TODO Where does this number come from?
private static final long DEFAULT_COLLECTION_SIZE = 536_870_912;
+ /**
+ * Creates a new builder.
+ *
+ * @param <B> The builder type.
+ * @return a new builder.
+ */
@PluginBuilderFactory
public static <B extends Builder<B>> B newBuilder() {
return new Builder<B>().asBuilder();
diff --git a/src/changelog/.2.x.x/3151_fix_mongodb_appender_deprecation_warning.xml b/src/changelog/.2.x.x/3151_fix_mongodb_appender_deprecation_warning.xml
new file mode 100644
index 0000000000..77837fc449
--- /dev/null
+++ b/src/changelog/.2.x.x/3151_fix_mongodb_appender_deprecation_warning.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="https://logging.apache.org/xml/ns"
+ xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="changed">
+ <issue id="3149" link="https://github.com/apache/logging-log4j2/issues/3151"/>
+ <description format="asciidoc">The MongoDb Appender shouldn't log a deprecation warning, GitHub issue #3151.</description>
+</entry>