vy commented on code in PR #3322: URL: https://github.com/apache/logging-log4j2/pull/3322#discussion_r1955688832
########## src/site/antora/modules/ROOT/pages/manual/appenders/database.adoc: ########## @@ -817,6 +817,29 @@ for its format. **Required** +| [[MongoDbProvider-attr-databaseName]]databaseName +| 'string' Review Comment: ```suggestion | `string` ``` ########## src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.json: ########## Review Comment: I prefer all `nosql-mongo*` file changes to be reverted to their old state where only the `connection` attribute is used. Old approach is simpler and fits the bill for most use cases. Users needing further customization can always refer to the manual, and reach out the `collectionName` & `databaseName` attributes. ########## log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbProviderTest.java: ########## @@ -0,0 +1,123 @@ +/* + * 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 static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.Test; + +class MongoDbProviderTest { + + private String validConnectionStringWithoutDatabase = "mongodb://localhost:27017"; + private String validConnectionStringWithDatabase = "mongodb://localhost:27017/logging"; + private String validConnectionStringWithDatabaseAndCollection = "mongodb://localhost:27017/logging.logs"; + + private String collectionName = "logsTest"; + private String databaseName = "loggingTest"; Review Comment: *Nit:* Could you make all these `private static final`, please? (I think you can also rename `validConnectionStringFoo` to `CON_STR_FOO` to save some visual real estate.) ########## src/site/antora/modules/ROOT/pages/manual/appenders/database.adoc: ########## @@ -817,6 +817,29 @@ for its format. **Required** +| [[MongoDbProvider-attr-databaseName]]databaseName +| 'string' +| +| +It specifies the name of the database for the appender to use. + +Overrides the value provided in the connection string if present. + +**Required** + +| [[MongoDbProvider-attr-collectionName]]collectionName +| 'string' +| +| +It specifies the name of the collection for the appender to use. +For backward compatibility, the collection name can also be specified in the +https://mongodb.github.io/mongo-java-driver/5.0/apidocs/mongodb-driver-core/com/mongodb/ConnectionString.html[Java-specific connection string] Review Comment: ```suggestion https://mongodb.github.io/mongo-java-driver/5.0/apidocs/mongodb-driver-core/com/mongodb/ConnectionString.html[Java-specific connection string]. ``` ########## log4j-mongodb/src/test/resources/MongoDbAdditionalFields.xml: ########## Review Comment: I see you switched all IT configuration to use the new `{database,collection}Name` attributes, don't. This effectively removes the checks verifying that the old style is still working. Could you revert all your `resources/*.xml` changes, please? (Keep the new resource files you added for new tests.) ########## src/changelog/.3.x.x/update_org_log4j_mongodb.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="added"> + <issue id="3321" link="https://github.com/apache/logging-log4j2/discussions/3321"/> + <description format="asciidoc">Update log4j-mongodb to allow collectionName and databaseName to be defined via the config file</description> Review Comment: ```suggestion <issue id="3322" link="https://github.com/apache/logging-log4j2/pull/3322"/> <description format="asciidoc">Add `collectionName` and `databaseName` arguments to the MongoDB appender</description> ``` ########## src/site/antora/modules/ROOT/pages/manual/appenders/database.adoc: ########## @@ -817,6 +817,29 @@ for its format. **Required** +| [[MongoDbProvider-attr-databaseName]]databaseName +| 'string' +| +| +It specifies the name of the database for the appender to use. + +Overrides the value provided in the connection string if present. + +**Required** + +| [[MongoDbProvider-attr-collectionName]]collectionName +| 'string' Review Comment: ```suggestion | `string` ``` ########## log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbProviderTest.java: ########## @@ -0,0 +1,123 @@ +/* + * 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 static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.Test; + +class MongoDbProviderTest { + + private String validConnectionStringWithoutDatabase = "mongodb://localhost:27017"; + private String validConnectionStringWithDatabase = "mongodb://localhost:27017/logging"; + private String validConnectionStringWithDatabaseAndCollection = "mongodb://localhost:27017/logging.logs"; + + private String collectionName = "logsTest"; + private String databaseName = "loggingTest"; + + @Test + void createProviderWithDatabaseAndCollectionProvidedViaConfig() { + + MongoDbProvider provider = MongoDbProvider.newBuilder() + .setConnectionStringSource(this.validConnectionStringWithoutDatabase) + .setDatabaseName(this.databaseName) + .setCollectionName(this.collectionName) + .build(); + + assertNotNull(provider, "Returned provider is null"); + assertEquals( + this.collectionName, + provider.getConnection().getCollection().getNamespace().getCollectionName(), + "Collection names do not match"); + assertEquals( + this.databaseName, + provider.getConnection().getCollection().getNamespace().getDatabaseName(), + "Database names do not match"); Review Comment: All checks are pretty self-explanatory. Could you remove all messages (`Returned provider is null`, `Collection names do not match`, etc.), please? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org