Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
770ca32
Backported changes from the 3.x branch to 2.x
jesmith17 Feb 15, 2025
821b77f
Fixed some details in unit tests
jesmith17 Feb 15, 2025
8c0e3c6
Improve configuration error handling of HttpAppender (#3438)
Suvrat1629 Feb 16, 2025
180b050
Removed wildcard imports from tests
jesmith17 Feb 16, 2025
67c70b9
Merge branch '2.x' of github.com:jesmith17/logging-log4j2 into jesmit…
vy Feb 17, 2025
82b30c5
Improve `database.adoc`
vy Feb 17, 2025
1c2bcf8
Fix changelog entry
vy Feb 17, 2025
140aa29
Fix XSD versions
vy Feb 17, 2025
8602d73
Revert changes to resources of old tests
vy Feb 17, 2025
eac41a5
Fixed formatting
jesmith17 Feb 18, 2025
01d0b81
Fixed constructors to prevent potential backwards compat issues
jesmith17 Feb 18, 2025
f328147
Rewmoving maven wrapper that got created locally to solve build issues
jesmith17 Feb 18, 2025
d79431b
Publish build scans to develocity.apache.org (#3396)
clayburn Feb 18, 2025
fdb3e7d
Fix null termination advice for SOA and JTL
vy Feb 18, 2025
81ba7a4
Bump org.apache.logging:logging-parent from 11.3.0 to 12.0.0 in /log4…
dependabot[bot] Feb 18, 2025
00eb8f4
Run reproducibility check after each deployment
ppkarwasz Oct 17, 2024
4276c2b
Run integration tests after each deployment (#3105)
ppkarwasz Feb 18, 2025
701845f
Fix revision to `2.25.0-SNAPSHOT`
ppkarwasz Feb 18, 2025
cb8c7ec
Fix Nexus URL for snapshots
ppkarwasz Feb 18, 2025
0a2566c
Update `org.apache.cassandra:cassandra-all` to version `3.11.19` (#3440)
asf-rm Feb 18, 2025
e4982fd
Activate `bom` profile in `log4j-bom`
ppkarwasz Feb 19, 2025
645502a
Add Nexus URL argument to `generate-email.sh` per `logging-parent` up…
vy Feb 19, 2025
8aaf288
Document `maven-compiler-plugin` override
vy Feb 19, 2025
0289d63
Update `org.mongodb:bson` to version `5.3.1` (#3409)
asf-rm Feb 19, 2025
530d850
Implement review feedback
vy Feb 19, 2025
0712cae
Restore `maven-wrapper.properties`
vy Feb 19, 2025
8eef677
Fix plugin names
vy Feb 19, 2025
2a052e1
Fix test resource files
vy Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 com.mongodb.client.MongoClient;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.junit.jupiter.api.Test;

@UsingMongoDb
@LoggerContextSource("MongoDbCollectionNameIT.xml")
// Print debug status logger output upon failure
@UsingStatusListener
class MongoDbCollectionNameIT extends AbstractMongoDbCappedIT {

@Test
@Override
protected void test(LoggerContext ctx, MongoClient mongoClient) {
super.test(ctx, mongoClient);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 com.mongodb.client.MongoClient;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.junit.jupiter.api.Test;

@UsingMongoDb
@LoggerContextSource("MongoDbDatabaseAndCollectionNameIT.xml")
// Print debug status logger output upon failure
@UsingStatusListener
class MongoDbDatabaseAndCollectionNameIT extends AbstractMongoDbCappedIT {

@Test
@Override
protected void test(LoggerContext ctx, MongoClient mongoClient) {
super.test(ctx, mongoClient);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 com.mongodb.client.MongoClient;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.junit.jupiter.api.Test;

@UsingMongoDb
@LoggerContextSource("MongoDbNoDatabaseAndCollectionNameIT.xml")
// Print debug status logger output upon failure
@UsingStatusListener
class MongoDbNoDatabaseAndCollectionNameIT extends AbstractMongoDbCappedIT {

@Test
@Override
protected void test(LoggerContext ctx, MongoClient mongoClient) {
super.test(ctx, mongoClient);
}
}
37 changes: 37 additions & 0 deletions log4j-mongodb/src/test/resources/MongoDbCollectionNameIT.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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 xmlns="https://logging.apache.org/xml/ns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
https://logging.apache.org/xml/ns
https://logging.apache.org/xml/ns/log4j-config-3.xsd">
<Appenders>
<NoSql name="MONGO">
<MongoDb
connection="mongodb://localhost:${sys:log4j.mongo.port:-27017}/testDb"
capped="true"
collectionSize="1073741824"
collectionName="MongoDbCollectionNameIT"/>
</NoSql>
</Appenders>
<Loggers>
<Root level="ALL">
<AppenderRef ref="MONGO" />
</Root>
</Loggers>
</Configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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 xmlns="https://logging.apache.org/xml/ns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
https://logging.apache.org/xml/ns
https://logging.apache.org/xml/ns/log4j-config-3.xsd">
<Appenders>
<NoSql name="MONGO">
<MongoDb
connection="mongodb://localhost:${sys:log4j.mongo.port:-27017}"
capped="true"
collectionSize="1073741824"
databaseName="testDb"
collectionName="MongoDbDatabaseAndCollectionNameIT"
/>
</NoSql>
</Appenders>
<Loggers>
<Root level="ALL">
<AppenderRef ref="MONGO" />
</Root>
</Loggers>
</Configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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 xmlns="https://logging.apache.org/xml/ns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
https://logging.apache.org/xml/ns
https://logging.apache.org/xml/ns/log4j-config-3.xsd">
<Appenders>
<NoSql name="MONGO">
<MongoDb
connection="mongodb://localhost:${sys:log4j.mongo.port:-27017}/testDb.MongoDbNoDatabaseAndCollectionNameIT"
capped="true"
collectionSize="1073741824"
/>
</NoSql>
</Appenders>
<Loggers>
<Root level="ALL">
<AppenderRef ref="MONGO" />
</Root>
</Loggers>
</Configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,23 @@ public MongoDb4Connection(
final ConnectionString connectionString,
final MongoClient mongoClient,
final MongoDatabase mongoDatabase,
final String collectionName,
final boolean isCapped,
final Integer sizeInBytes) {
this(connectionString, mongoClient, mongoDatabase, isCapped, Long.valueOf(sizeInBytes));
this(connectionString, mongoClient, mongoDatabase, collectionName, isCapped, Long.valueOf(sizeInBytes));
}

public MongoDb4Connection(
final ConnectionString connectionString,
final MongoClient mongoClient,
final MongoDatabase mongoDatabase,
final String collectionName,
final boolean isCapped,
final Long sizeInBytes) {
this.connectionString = connectionString;
this.mongoClient = mongoClient;
this.collection =
getOrCreateMongoCollection(mongoDatabase, connectionString.getCollection(), isCapped, sizeInBytes);
getOrCreateMongoCollection(mongoDatabase, collectionName, isCapped, sizeInBytes);
}

@Override
Expand Down Expand Up @@ -119,4 +121,12 @@ public String toString() {
"Mongo4Connection [connectionString=%s, collection=%s, mongoClient=%s]",
connectionString, collection, mongoClient);
}

/*
* This method is exposed to help support unit tests for the MongoDbProvider class.
*
*/
public MongoCollection<Document> getCollection() {
return this.collection;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoNamespace;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoDatabase;
Expand Down Expand Up @@ -60,14 +61,47 @@ public static class Builder<B extends Builder<B>> extends AbstractFilterable.Bui
@PluginBuilderAttribute("capped")
private boolean capped = false;

@PluginBuilderAttribute("collectionName")
private String collectionName;

@PluginBuilderAttribute("databaseName")
private String databaseName;



@Override
public MongoDb4Provider build() {
StatusLogger.getLogger().warn("The {} Appender is deprecated, use the MongoDb Appender.", PLUGIN_NAME);

ConnectionString connectionString;
try {
connectionString = new ConnectionString(connectionStringSource);
} catch (final IllegalArgumentException e) {
LOGGER.error("Invalid MongoDB connection string `{}`.", connectionStringSource, e);
return null;
}

String effectiveDatabaseName = databaseName != null ? databaseName : connectionString.getDatabase();
String effectiveCollectionName = collectionName != null ? collectionName : connectionString.getCollection();
// Validate the provided databaseName property
try {
MongoNamespace.checkDatabaseNameValidity(effectiveDatabaseName);
} catch (final IllegalArgumentException e) {
LOGGER.error("Invalid MongoDB database name `{}`.", effectiveDatabaseName, e);
return null;
}
// Validate the provided collectionName property
try {
MongoNamespace.checkCollectionNameValidity(effectiveCollectionName);
} catch (final IllegalArgumentException e) {
LOGGER.error("Invalid MongoDB collection name `{}`.", effectiveCollectionName, e);
return null;
}
return newMongoDb4Provider();
}

protected MongoDb4Provider newMongoDb4Provider() {
return new MongoDb4Provider(connectionStringSource, capped, collectionSize);
return new MongoDb4Provider(connectionStringSource, databaseName, collectionName, capped, collectionSize);
}

/**
Expand Down Expand Up @@ -113,6 +147,28 @@ public B setCollectionSize(final long sizeInBytes) {
this.collectionSize = sizeInBytes;
return asBuilder();
}

/**
* Sets name of the collection for the appender to output to
*
* @param collectionName the name of the collection for the appender to output to
* @return this instance.
*/
public B setCollectionName(final String collectionName) {
this.collectionName = collectionName;
return asBuilder();
}

/**
* Sets the name of the logical database for the appender to output to.
*
* @param databaseName the name of the DB for the appender to output to
* @return this instance.
*/
public B setDatabaseName(final String databaseName) {
this.databaseName = databaseName;
return asBuilder();
}
}

private static final Logger LOGGER = StatusLogger.getLogger();
Expand Down Expand Up @@ -140,11 +196,12 @@ public static <B extends Builder<B>> B newBuilder() {

private final Long collectionSize;
private final boolean isCapped;
private final String collectionName;
private final MongoClient mongoClient;
private final MongoDatabase mongoDatabase;
private final ConnectionString connectionString;

private MongoDb4Provider(final String connectionStringSource, final boolean isCapped, final Long collectionSize) {
private MongoDb4Provider(final String connectionStringSource, final String databaseName, final String collectionName, final boolean isCapped, final Long collectionSize) {
LOGGER.debug("Creating ConnectionString {}...", connectionStringSource);
this.connectionString = new ConnectionString(connectionStringSource);
LOGGER.debug("Created ConnectionString {}", connectionString);
Expand All @@ -159,28 +216,29 @@ private MongoDb4Provider(final String connectionStringSource, final boolean isCa
LOGGER.debug("Creating MongoClient {}...", settings);
this.mongoClient = MongoClients.create(settings);
LOGGER.debug("Created MongoClient {}", mongoClient);
final String databaseName = this.connectionString.getDatabase();
LOGGER.debug("Getting MongoDatabase {}...", databaseName);
this.mongoDatabase = this.mongoClient.getDatabase(databaseName);
LOGGER.debug("Got MongoDatabase {}", mongoDatabase);
this.isCapped = isCapped;
this.collectionSize = collectionSize;
this.collectionName = collectionName;
}

@Override
public MongoDb4Connection getConnection() {
return new MongoDb4Connection(connectionString, mongoClient, mongoDatabase, isCapped, collectionSize);
return new MongoDb4Connection(connectionString, mongoClient, mongoDatabase, collectionName, isCapped, collectionSize);
}

@Override
public String toString() {
return String.format(
"%s [connectionString=%s, collectionSize=%s, isCapped=%s, mongoClient=%s, mongoDatabase=%s]",
"%s [connectionString=%s, collectionSize=%s, isCapped=%s, mongoClient=%s, mongoDatabase=%s, collectionName=%s]",
MongoDb4Provider.class.getSimpleName(),
connectionString,
collectionSize,
isCapped,
mongoClient,
mongoDatabase);
mongoDatabase,
collectionName);
}
}
Loading
Loading