Skip to content

Commit c662e6f

Browse files
committed
The MongoDb Appender shouldn't log a deprecation warning, GitHub
issue apache#3151
1 parent db73c3a commit c662e6f

File tree

5 files changed

+82
-13
lines changed

5 files changed

+82
-13
lines changed

log4j-mongodb/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<!-- Dependency versions -->
3333
<mongodb.version>5.2.0</mongodb.version>
3434
<slf4j2.version>2.0.16</slf4j2.version>
35+
<!-- Using bnd.baseline.skip for weird complaints; why are we running this at all for an appender impl? -->
36+
<bnd.baseline.skip>true</bnd.baseline.skip>
3537
</properties>
3638
<dependencyManagement>
3739
<dependencies>

log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbProvider.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,43 @@
2222
import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
2323
import org.apache.logging.log4j.mongodb4.MongoDb4Connection;
2424
import org.apache.logging.log4j.mongodb4.MongoDb4Provider;
25-
import org.apache.logging.log4j.mongodb4.MongoDb4Provider.Builder;
2625

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

40-
private MongoDbProvider() {}
36+
/**
37+
* Builds new {@link MongoDb4Provider} instance.
38+
*/
39+
public static class Builder extends MongoDb4Provider.Builder<Builder> {
4140

41+
@Override
42+
public MongoDb4Provider build() {
43+
// Don't issue MongoDb4Provider's WARN event.
44+
return newMongoDb4Provider();
45+
}
46+
}
47+
48+
/**
49+
* There are no instances.
50+
*/
51+
private MongoDbProvider() {
52+
// empty.
53+
}
54+
55+
/**
56+
* Creates a new builder.
57+
*
58+
* @return a new builder.
59+
*/
4260
@PluginBuilderFactory
43-
public static <B extends Builder<B>> B newBuilder() {
44-
return MongoDb4Provider.newBuilder();
61+
public static Builder newBuilder() {
62+
return new Builder();
4563
}
4664
}

log4j-mongodb4/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
<!-- Dependency versions -->
3838
<mongodb4.version>4.11.4</mongodb4.version>
3939
<slf4j.version>2.0.16</slf4j.version>
40+
<!-- Using bnd.baseline.skip for weird complaints; why are we running this at all for an appender impl? -->
41+
<bnd.baseline.skip>true</bnd.baseline.skip>
4042
</properties>
4143

4244
<dependencyManagement>

log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4Provider.java

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public final class MongoDb4Provider implements NoSqlProvider<MongoDb4Connection>
4242

4343
static final String PLUGIN_NAME = "MongoDb4";
4444

45+
/**
46+
* Builds new {@link MongoDb4Provider} instance.
47+
*
48+
* @param <B> the builder type.
49+
*/
4550
public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B>
4651
implements org.apache.logging.log4j.core.util.Builder<MongoDb4Provider> {
4752

@@ -58,26 +63,54 @@ public static class Builder<B extends Builder<B>> extends AbstractFilterable.Bui
5863
@Override
5964
public MongoDb4Provider build() {
6065
StatusLogger.getLogger().warn("The {} Appender is deprecated, use the MongoDb Appender.", PLUGIN_NAME);
66+
return newMongoDb4Provider();
67+
}
68+
69+
protected MongoDb4Provider newMongoDb4Provider() {
6170
return new MongoDb4Provider(connectionStringSource, capped, collectionSize);
6271
}
6372

73+
/**
74+
* Sets the MongoDB connection string.
75+
*
76+
* @param connectionStringSource the MongoDB connection string.
77+
* @return this instance.
78+
*/
6479
public B setConnectionStringSource(final String connectionStringSource) {
6580
this.connectionStringSource = connectionStringSource;
6681
return asBuilder();
6782
}
6883

84+
/**
85+
* Sets whether the MongoDB collection is capped.
86+
*
87+
* @param isCapped whether the MongoDB collection is capped.
88+
* @return this instance.
89+
*/
6990
public B setCapped(final boolean isCapped) {
7091
this.capped = isCapped;
7192
return asBuilder();
7293
}
7394

74-
public B setCollectionSize(final int collectionSize) {
75-
this.collectionSize = collectionSize;
95+
/**
96+
* Sets the maximum size in bytes of a capped collection.
97+
*
98+
* @param sizeInBytes the maximum size in bytes of a capped collection.
99+
* @return this instance.
100+
*/
101+
public B setCollectionSize(final int sizeInBytes) {
102+
this.collectionSize = sizeInBytes;
76103
return asBuilder();
77104
}
78105

79-
public B setCollectionSize(final long collectionSize) {
80-
this.collectionSize = collectionSize;
106+
/**
107+
* Sets the maximum size in bytes of a capped collection.
108+
*
109+
* @param sizeInBytes the maximum size in bytes of a capped collection.
110+
* @return this instance.
111+
*/
112+
public B setCollectionSize(final long sizeInBytes) {
113+
this.collectionSize = sizeInBytes;
81114
return asBuilder();
82115
}
83116
}
@@ -94,6 +127,12 @@ public B setCollectionSize(final long collectionSize) {
94127
// TODO Where does this number come from?
95128
private static final long DEFAULT_COLLECTION_SIZE = 536_870_912;
96129

130+
/**
131+
* Creates a new builder.
132+
*
133+
* @param <B> The builder type.
134+
* @return a new builder.
135+
*/
97136
@PluginBuilderFactory
98137
public static <B extends Builder<B>> B newBuilder() {
99138
return new Builder<B>().asBuilder();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="https://logging.apache.org/xml/ns"
4+
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
5+
type="changed">
6+
<issue id="3149" link="https://github.com/apache/logging-log4j2/issues/3151"/>
7+
<description format="asciidoc">The MongoDb Appender shouldn't log a deprecation warning, GitHub issue #3151.</description>
8+
</entry>

0 commit comments

Comments
 (0)