diff --git a/.github/generate-email.sh b/.github/generate-email.sh index e825293af6d..469023ad819 100755 --- a/.github/generate-email.sh +++ b/.github/generate-email.sh @@ -28,12 +28,12 @@ stderr() { fail_for_invalid_args() { stderr "Invalid arguments!" - stderr "Expected arguments: " + stderr "Expected arguments: " exit 1 } # Check arguments -[ $# -ne 3 ] && fail_for_invalid_args +[ $# -ne 4 ] && fail_for_invalid_args # Constants PROJECT_NAME="Apache Log4j" @@ -43,6 +43,7 @@ PROJECT_SITE="https://logging.apache.org/$PROJECT_ID" PROJECT_STAGING_SITE="${PROJECT_SITE/apache.org/staged.apache.org}" PROJECT_REPO="https://github.com/apache/logging-log4j2" COMMIT_ID="$3" +NEXUS_URL="$4" PROJECT_DIST_URL="https://dist.apache.org/repos/dist/dev/logging/$PROJECT_ID/$PROJECT_VERSION" # Check release notes file @@ -71,7 +72,7 @@ Website: $PROJECT_STAGING_SITE/$PROJECT_VERSION/index.html GitHub: $PROJECT_REPO Commit: $COMMIT_ID Distribution: $PROJECT_DIST_URL -Nexus: https://repository.apache.org/content/repositories/orgapachelogging- +Nexus: $NEXUS_URL Signing key: 0x077e8893a6dcc33dd4a4d5b256e73ba9a0b592d0 Review kit: https://logging.apache.org/logging-parent/release-review-instructions.html diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ac7d6128ffc..3e5377d03c1 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -30,21 +30,21 @@ jobs: build: if: github.actor != 'dependabot[bot]' - uses: apache/logging-parent/.github/workflows/build-reusable.yaml@rel/11.3.0 + uses: apache/logging-parent/.github/workflows/build-reusable.yaml@rel/12.0.0 secrets: - DV_ACCESS_TOKEN: ${{ startsWith(github.ref_name, 'release/') && '' || secrets.GE_ACCESS_TOKEN }} + DV_ACCESS_TOKEN: ${{ startsWith(github.ref_name, 'release/') && '' || secrets.DEVELOCITY_ACCESS_KEY }} with: java-version: | 8 17 site-enabled: true - reproducibility-check-enabled: ${{ startsWith(github.ref_name, 'release/') }} + reproducibility-check-enabled: false develocity-enabled: ${{ ! startsWith(github.ref_name, 'release/') }} deploy-snapshot: needs: build if: github.repository == 'apache/logging-log4j2' && github.ref_name == '2.x' - uses: apache/logging-parent/.github/workflows/deploy-snapshot-reusable.yaml@rel/11.3.0 + uses: apache/logging-parent/.github/workflows/deploy-snapshot-reusable.yaml@rel/12.0.0 # Secrets for deployments secrets: NEXUS_USERNAME: ${{ secrets.NEXUS_USER }} @@ -57,7 +57,7 @@ jobs: deploy-release: needs: build if: github.repository == 'apache/logging-log4j2' && startsWith(github.ref_name, 'release/') - uses: apache/logging-parent/.github/workflows/deploy-release-reusable.yaml@rel/11.3.0 + uses: apache/logging-parent/.github/workflows/deploy-release-reusable.yaml@rel/12.0.0 # Secrets for deployments secrets: GPG_SECRET_KEY: ${{ secrets.LOGGING_GPG_SECRET_KEY }} @@ -73,3 +73,25 @@ jobs: 8 17 project-id: log4j + + verify-reproducibility: + needs: [ deploy-snapshot, deploy-release ] + if: ${{ always() && (needs.deploy-snapshot.result == 'success' || needs.deploy-release.result == 'success') }} + name: "verify-reproducibility (${{ needs.deploy-release.result == 'success' && needs.deploy-release.outputs.project-version || needs.deploy-snapshot.outputs.project-version }})" + uses: apache/logging-parent/.github/workflows/verify-reproducibility-reusable.yaml@rel/12.0.0 + with: + nexus-url: ${{ needs.deploy-release.result == 'success' && needs.deploy-release.outputs.nexus-url || 'https://repository.apache.org/content/groups/snapshots' }} + # Encode the `runs-on` input as JSON array + runs-on: '["ubuntu-latest", "macos-latest", "windows-latest"]' + + # Run integration-tests automatically after a snapshot or RC is published + integration-test: + needs: [ deploy-snapshot, deploy-release ] + if: ${{ always() && (needs.deploy-snapshot.result == 'success' || needs.deploy-release.result == 'success') }} + name: "integration-test (${{ needs.deploy-release.result == 'success' && needs.deploy-release.outputs.project-version || needs.deploy-snapshot.outputs.project-version }})" + uses: apache/logging-log4j-samples/.github/workflows/integration-test.yaml@main + with: + log4j-version: ${{ needs.deploy-release.result == 'success' && needs.deploy-release.outputs.project-version || needs.deploy-snapshot.outputs.project-version }} + log4j-repository-url: ${{ needs.deploy-release.result == 'success' && needs.deploy-release.outputs.nexus-url || needs.deploy-snapshot.outputs.nexus-url }} + # Use the `main` branch of `logging-log4j-samples` + samples-ref: 'refs/heads/main' diff --git a/.github/workflows/codeql-analysis.yaml b/.github/workflows/codeql-analysis.yaml index cc2dbcaaf85..05a37e02f99 100644 --- a/.github/workflows/codeql-analysis.yaml +++ b/.github/workflows/codeql-analysis.yaml @@ -30,7 +30,7 @@ permissions: read-all jobs: analyze: - uses: apache/logging-parent/.github/workflows/codeql-analysis-reusable.yaml@rel/11.3.0 + uses: apache/logging-parent/.github/workflows/codeql-analysis-reusable.yaml@rel/12.0.0 with: java-version: | 8 diff --git a/.github/workflows/deploy-site.yaml b/.github/workflows/deploy-site.yaml index 365b8fc2901..604ac5f63aa 100644 --- a/.github/workflows/deploy-site.yaml +++ b/.github/workflows/deploy-site.yaml @@ -33,7 +33,7 @@ jobs: deploy-site-stg: if: github.repository == 'apache/logging-log4j2' && github.ref_name == '2.x' - uses: apache/logging-parent/.github/workflows/deploy-site-reusable.yaml@rel/11.3.0 + uses: apache/logging-parent/.github/workflows/deploy-site-reusable.yaml@rel/12.0.0 # Secrets for committing the generated site secrets: GPG_SECRET_KEY: ${{ secrets.LOGGING_GPG_SECRET_KEY }} @@ -51,7 +51,7 @@ jobs: deploy-site-pro: if: github.repository == 'apache/logging-log4j2' && github.ref_name == '2.x-site-pro' - uses: apache/logging-parent/.github/workflows/deploy-site-reusable.yaml@rel/11.3.0 + uses: apache/logging-parent/.github/workflows/deploy-site-reusable.yaml@rel/12.0.0 # Secrets for committing the generated site secrets: GPG_SECRET_KEY: ${{ secrets.LOGGING_GPG_SECRET_KEY }} @@ -81,7 +81,7 @@ jobs: deploy-site-rel: needs: export-version - uses: apache/logging-parent/.github/workflows/deploy-site-reusable.yaml@rel/11.3.0 + uses: apache/logging-parent/.github/workflows/deploy-site-reusable.yaml@rel/12.0.0 # Secrets for committing the generated site secrets: GPG_SECRET_KEY: ${{ secrets.LOGGING_GPG_SECRET_KEY }} diff --git a/.github/workflows/develocity-publish-build-scans.yaml b/.github/workflows/develocity-publish-build-scans.yaml index 78069943bb0..31fa075ac2f 100644 --- a/.github/workflows/develocity-publish-build-scans.yaml +++ b/.github/workflows/develocity-publish-build-scans.yaml @@ -38,5 +38,5 @@ jobs: - name: Publish Build Scans uses: gradle/develocity-actions/maven-publish-build-scan@b8d3a572314ffff3b940a2c1b7b384d4983d422d # 1.3 with: - develocity-url: 'https://ge.apache.org' - develocity-access-key: ${{ secrets.GE_ACCESS_TOKEN }} + develocity-url: 'https://develocity.apache.org' + develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }} diff --git a/.github/workflows/merge-dependabot.yaml b/.github/workflows/merge-dependabot.yaml index 4e35def4b67..cfb0b1d63dd 100644 --- a/.github/workflows/merge-dependabot.yaml +++ b/.github/workflows/merge-dependabot.yaml @@ -30,9 +30,9 @@ jobs: build: if: github.repository == 'apache/logging-log4j2' && github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]' - uses: apache/logging-parent/.github/workflows/build-reusable.yaml@rel/11.3.0 + uses: apache/logging-parent/.github/workflows/build-reusable.yaml@rel/12.0.0 secrets: - DV_ACCESS_TOKEN: ${{ secrets.GE_ACCESS_TOKEN }} + DV_ACCESS_TOKEN: ${{ secrets.DEVELOCITY_ACCESS_KEY }} with: java-version: | 8 @@ -42,7 +42,7 @@ jobs: merge-dependabot: needs: build - uses: apache/logging-parent/.github/workflows/merge-dependabot-reusable.yaml@rel/11.3.0 + uses: apache/logging-parent/.github/workflows/merge-dependabot-reusable.yaml@rel/12.0.0 with: java-version: 17 permissions: diff --git a/.logging-parent-bom-activator b/.logging-parent-bom-activator new file mode 100644 index 00000000000..e7980a6d13b --- /dev/null +++ b/.logging-parent-bom-activator @@ -0,0 +1,16 @@ +# 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. +## +This file activates the `flatten-bom` profile. \ No newline at end of file diff --git a/.mvn/develocity.xml b/.mvn/develocity.xml index 84def1dec34..caa112766a0 100644 --- a/.mvn/develocity.xml +++ b/.mvn/develocity.xml @@ -2,7 +2,7 @@ logging-log4j2 - https://ge.apache.org + https://develocity.apache.org diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderBuilderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderBuilderTest.java new file mode 100644 index 00000000000..2680961d19c --- /dev/null +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderBuilderTest.java @@ -0,0 +1,130 @@ +/* + * 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.core.appender; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.net.MalformedURLException; +import java.net.URL; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.DefaultConfiguration; +import org.apache.logging.log4j.core.config.Property; +import org.apache.logging.log4j.core.layout.JsonLayout; +import org.apache.logging.log4j.core.net.ssl.SslConfiguration; +import org.apache.logging.log4j.test.ListStatusListener; +import org.apache.logging.log4j.test.junit.UsingStatusListener; +import org.junit.jupiter.api.Test; + +class HttpAppenderBuilderTest { + + private HttpAppender.Builder getBuilder() { + Configuration mockConfig = new DefaultConfiguration(); + return HttpAppender.newBuilder().setConfiguration(mockConfig).setName("TestHttpAppender"); // Name is required + } + + @Test + @UsingStatusListener + void testBuilderWithoutUrl(final ListStatusListener listener) throws Exception { + HttpAppender appender = HttpAppender.newBuilder() + .setConfiguration(new DefaultConfiguration()) + .setName("TestAppender") + .setLayout(JsonLayout.createDefaultLayout()) // Providing a layout here + .build(); + + assertThat(listener.findStatusData(Level.ERROR)) + .anyMatch(statusData -> + statusData.getMessage().getFormattedMessage().contains("HttpAppender requires URL to be set.")); + } + + @Test + @UsingStatusListener + void testBuilderWithUrlAndWithoutLayout(final ListStatusListener listener) throws Exception { + HttpAppender appender = HttpAppender.newBuilder() + .setConfiguration(new DefaultConfiguration()) + .setName("TestAppender") + .setUrl(new URL("http://localhost:8080/logs")) + .build(); + + assertThat(listener.findStatusData(Level.ERROR)).anyMatch(statusData -> statusData + .getMessage() + .getFormattedMessage() + .contains("HttpAppender requires a layout to be set.")); + } + + @Test + void testBuilderWithValidConfiguration() throws Exception { + URL url = new URL("http://example.com"); + Layout layout = JsonLayout.createDefaultLayout(); + + HttpAppender.Builder builder = getBuilder().setUrl(url).setLayout(layout); + + HttpAppender appender = builder.build(); + assertNotNull(appender, "HttpAppender should be created with valid configuration."); + } + + @Test + void testBuilderWithCustomMethod() throws Exception { + URL url = new URL("http://example.com"); + Layout layout = JsonLayout.createDefaultLayout(); + String customMethod = "PUT"; + + HttpAppender.Builder builder = + getBuilder().setUrl(url).setLayout(layout).setMethod(customMethod); + + HttpAppender appender = builder.build(); + assertNotNull(appender, "HttpAppender should be created with a custom HTTP method."); + } + + @Test + void testBuilderWithHeaders() throws Exception { + URL url = new URL("http://example.com"); + Layout layout = JsonLayout.createDefaultLayout(); + Property[] headers = new Property[] { + Property.createProperty("Header1", "Value1"), Property.createProperty("Header2", "Value2") + }; + + HttpAppender.Builder builder = + getBuilder().setUrl(url).setLayout(layout).setHeaders(headers); + + HttpAppender appender = builder.build(); + assertNotNull(appender, "HttpAppender should be created with headers."); + } + + @Test + void testBuilderWithSslConfiguration() throws Exception { + URL url = new URL("https://example.com"); + Layout layout = JsonLayout.createDefaultLayout(); + + // Use real SslConfiguration instead of Mockito mock + SslConfiguration sslConfig = SslConfiguration.createSSLConfiguration(null, null, null, false); + + HttpAppender.Builder builder = + getBuilder().setUrl(url).setLayout(layout).setSslConfiguration(sslConfig); + + HttpAppender appender = builder.build(); + assertNotNull(appender, "HttpAppender should be created with SSL configuration."); + } + + @Test + void testBuilderWithInvalidUrl() { + assertThrows(MalformedURLException.class, () -> new URL("invalid-url")); + } +} diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java index b24e165b3e1..56d1ffb5e37 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java @@ -32,16 +32,15 @@ import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required; import org.apache.logging.log4j.core.net.ssl.SslConfiguration; +import org.apache.logging.log4j.status.StatusLogger; -/** - * Sends log events over HTTP. - */ @Plugin(name = "Http", category = Node.CATEGORY, elementType = Appender.ELEMENT_TYPE, printObject = true) public final class HttpAppender extends AbstractAppender { + private static final StatusLogger LOGGER = StatusLogger.getLogger(); + /** * Builds HttpAppender instances. - * @param The type to build */ public static class Builder> extends AbstractAppender.Builder implements org.apache.logging.log4j.core.util.Builder { @@ -70,6 +69,18 @@ public static class Builder> extends AbstractAppender.Build @Override public HttpAppender build() { + // Validate URL presence + if (url == null) { + LOGGER.error("HttpAppender requires URL to be set."); + return null; // Return null if URL is missing + } + + // Validate layout presence + if (getLayout() == null) { + LOGGER.error("HttpAppender requires a layout to be set."); + return null; // Return null if layout is missing + } + final HttpManager httpManager = new HttpURLConnectionManager( getConfiguration(), getConfiguration().getLoggerContext(), @@ -81,10 +92,12 @@ public HttpAppender build() { headers, sslConfiguration, verifyHostname); + return new HttpAppender( getName(), getLayout(), getFilter(), isIgnoreExceptions(), httpManager, getPropertyArray()); } + // Getter and Setter methods public URL getUrl() { return url; } @@ -149,9 +162,6 @@ public B setVerifyHostname(final boolean verifyHostname) { } } - /** - * @return a builder for a HttpAppender. - */ @PluginBuilderFactory public static > B newBuilder() { return new Builder().asBuilder(); diff --git a/log4j-mongodb/pom.xml b/log4j-mongodb/pom.xml index 4991ab5ac83..822f4d382db 100644 --- a/log4j-mongodb/pom.xml +++ b/log4j-mongodb/pom.xml @@ -30,7 +30,7 @@ org.apache.logging.log4j.core - 5.2.1 + 5.3.1 2.0.16 diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCollectionNameIT.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCollectionNameIT.java new file mode 100644 index 00000000000..60c74dff597 --- /dev/null +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbCollectionNameIT.java @@ -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); + } +} diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbDatabaseAndCollectionNameIT.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbDatabaseAndCollectionNameIT.java new file mode 100644 index 00000000000..8d399d10ac9 --- /dev/null +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbDatabaseAndCollectionNameIT.java @@ -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); + } +} diff --git a/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbNoDatabaseAndCollectionNameIT.java b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbNoDatabaseAndCollectionNameIT.java new file mode 100644 index 00000000000..ba6a654fdb9 --- /dev/null +++ b/log4j-mongodb/src/test/java/org/apache/logging/log4j/mongodb/MongoDbNoDatabaseAndCollectionNameIT.java @@ -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); + } +} diff --git a/log4j-mongodb/src/test/resources/MongoDbCollectionNameIT.xml b/log4j-mongodb/src/test/resources/MongoDbCollectionNameIT.xml new file mode 100644 index 00000000000..4b9b53842ed --- /dev/null +++ b/log4j-mongodb/src/test/resources/MongoDbCollectionNameIT.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + diff --git a/log4j-mongodb/src/test/resources/MongoDbDatabaseAndCollectionNameIT.xml b/log4j-mongodb/src/test/resources/MongoDbDatabaseAndCollectionNameIT.xml new file mode 100644 index 00000000000..b23b551fa21 --- /dev/null +++ b/log4j-mongodb/src/test/resources/MongoDbDatabaseAndCollectionNameIT.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + diff --git a/log4j-mongodb/src/test/resources/MongoDbNoDatabaseAndCollectionNameIT.xml b/log4j-mongodb/src/test/resources/MongoDbNoDatabaseAndCollectionNameIT.xml new file mode 100644 index 00000000000..0068ab3ee38 --- /dev/null +++ b/log4j-mongodb/src/test/resources/MongoDbNoDatabaseAndCollectionNameIT.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + diff --git a/log4j-mongodb4/pom.xml b/log4j-mongodb4/pom.xml index fc25d4ace9a..9115fe4175f 100644 --- a/log4j-mongodb4/pom.xml +++ b/log4j-mongodb4/pom.xml @@ -134,16 +134,6 @@ org.apache.maven.plugins maven-surefire-plugin - - true - - - - org.junit.jupiter - junit-jupiter-engine - ${junit-jupiter.version} - - @@ -236,11 +226,6 @@ **/*IT.java - - OFF ${mongo.port} diff --git a/log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4Connection.java b/log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4Connection.java index 1d9537978c4..dd7a3a927c1 100644 --- a/log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4Connection.java +++ b/log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4Connection.java @@ -41,7 +41,7 @@ public final class MongoDb4Connection extends AbstractNoSqlConnection getOrCreateMongoCollection( final MongoDatabase database, final String collectionName, final boolean isCapped, final Long sizeInBytes) { try { - LOGGER.debug("Gettting collection '{}'...", collectionName); + LOGGER.debug("Getting collection '{}'...", collectionName); // throws IllegalArgumentException if collectionName is invalid final MongoCollection found = database.getCollection(collectionName); LOGGER.debug("Got collection {}", found); @@ -63,15 +63,29 @@ private static MongoCollection getOrCreateMongoCollection( private final MongoCollection collection; private final MongoClient mongoClient; + /** + * @deprecated Use {@link #MongoDb4Connection(ConnectionString, MongoClient, MongoDatabase, String, boolean, Long)} instead + */ + @Deprecated public MongoDb4Connection( final ConnectionString connectionString, final MongoClient mongoClient, final MongoDatabase mongoDatabase, final boolean isCapped, final Integer sizeInBytes) { - this(connectionString, mongoClient, mongoDatabase, isCapped, Long.valueOf(sizeInBytes)); + this( + connectionString, + mongoClient, + mongoDatabase, + connectionString.getCollection(), + isCapped, + Long.valueOf(sizeInBytes)); } + /** + * @deprecated Use {@link #MongoDb4Connection(ConnectionString, MongoClient, MongoDatabase, String, boolean, Long)} instead + */ + @Deprecated public MongoDb4Connection( final ConnectionString connectionString, final MongoClient mongoClient, @@ -84,6 +98,18 @@ public MongoDb4Connection( getOrCreateMongoCollection(mongoDatabase, connectionString.getCollection(), isCapped, 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, collectionName, isCapped, sizeInBytes); + } + @Override public void closeImpl() { // LOG4J2-1196 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 99e392237b4..18cf93f2356 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 @@ -18,10 +18,10 @@ 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; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.appender.nosql.NoSqlProvider; import org.apache.logging.log4j.core.config.plugins.Plugin; @@ -40,6 +40,8 @@ @Plugin(name = MongoDb4Provider.PLUGIN_NAME, category = Core.CATEGORY_NAME, printObject = true) public final class MongoDb4Provider implements NoSqlProvider { + private static final StatusLogger LOGGER = StatusLogger.getLogger(); + static final String PLUGIN_NAME = "MongoDb4"; /** @@ -60,14 +62,20 @@ public static class Builder> 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); + LOGGER.warn("The {} Appender is deprecated, use the MongoDb Appender instead.", PLUGIN_NAME); return newMongoDb4Provider(); } protected MongoDb4Provider newMongoDb4Provider() { - return new MongoDb4Provider(connectionStringSource, capped, collectionSize); + return new MongoDb4Provider(connectionStringSource, databaseName, collectionName, capped, collectionSize); } /** @@ -113,16 +121,34 @@ public B setCollectionSize(final long sizeInBytes) { this.collectionSize = sizeInBytes; return asBuilder(); } - } - private static final Logger LOGGER = StatusLogger.getLogger(); + /** + * 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(); + } + } - // @formatter:off private static final CodecRegistry CODEC_REGISTRIES = CodecRegistries.fromRegistries( MongoClientSettings.getDefaultCodecRegistry(), CodecRegistries.fromCodecs(MongoDb4LevelCodec.INSTANCE), CodecRegistries.fromCodecs(new MongoDb4DocumentObjectCodec())); - // @formatter:on // TODO Where does this number come from? private static final long DEFAULT_COLLECTION_SIZE = 536_870_912; @@ -140,47 +166,81 @@ public static > 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) { - LOGGER.debug("Creating ConnectionString {}...", connectionStringSource); - this.connectionString = new ConnectionString(connectionStringSource); - LOGGER.debug("Created ConnectionString {}", connectionString); - LOGGER.debug("Creating MongoClientSettings..."); - // @formatter:off + private MongoDb4Provider( + final String connectionStringSource, + final String databaseName, + final String collectionName, + final boolean isCapped, + final Long collectionSize) { + this.connectionString = createConnectionString(connectionStringSource); final MongoClientSettings settings = MongoClientSettings.builder() .applyConnectionString(this.connectionString) .codecRegistry(CODEC_REGISTRIES) .build(); - // @formatter:on - LOGGER.debug("Created MongoClientSettings {}", settings); - 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.mongoDatabase = createDatabase(connectionString, databaseName, mongoClient); this.isCapped = isCapped; this.collectionSize = collectionSize; + this.collectionName = getEffectiveCollectionName(connectionString, collectionName); + LOGGER.debug("instantiated {}", this); + } + + private static ConnectionString createConnectionString(final String connectionStringSource) { + try { + return new ConnectionString(connectionStringSource); + } catch (final IllegalArgumentException error) { + final String message = String.format("Invalid MongoDB connection string: `%s`", connectionStringSource); + throw new IllegalArgumentException(message, error); + } + } + + private static MongoDatabase createDatabase( + final ConnectionString connectionString, final String databaseName, final MongoClient client) { + final String effectiveDatabaseName = databaseName != null ? databaseName : connectionString.getDatabase(); + try { + // noinspection DataFlowIssue + MongoNamespace.checkDatabaseNameValidity(effectiveDatabaseName); + } catch (final IllegalArgumentException error) { + final String message = String.format("Invalid MongoDB database name: `%s`", effectiveDatabaseName); + throw new IllegalArgumentException(message, error); + } + return client.getDatabase(effectiveDatabaseName); + } + + private static String getEffectiveCollectionName( + final ConnectionString connectionString, final String collectionName) { + final String effectiveCollectionName = + collectionName != null ? collectionName : connectionString.getCollection(); + try { + // noinspection DataFlowIssue + MongoNamespace.checkCollectionNameValidity(effectiveCollectionName); + } catch (final IllegalArgumentException error) { + final String message = String.format("Invalid MongoDB collection name: `%s`", effectiveCollectionName); + throw new IllegalArgumentException(message, error); + } + return effectiveCollectionName; } @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, databaseName=`%s`, collectionName=`%s`]", MongoDb4Provider.class.getSimpleName(), connectionString, collectionSize, isCapped, - mongoClient, - mongoDatabase); + mongoDatabase.getName(), + collectionName); } } diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/AbstractMongoDb4CappedIT.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/AbstractMongoDb4CappedIT.java index 07483dd3cf2..caac94e6b5e 100644 --- a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/AbstractMongoDb4CappedIT.java +++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/AbstractMongoDb4CappedIT.java @@ -24,6 +24,7 @@ import com.mongodb.client.MongoDatabase; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.status.StatusLogger; import org.bson.Document; abstract class AbstractMongoDb4CappedIT { @@ -33,8 +34,9 @@ protected void test(final LoggerContext ctx, final MongoClient mongoClient) { logger.info("Hello log"); final MongoDatabase database = mongoClient.getDatabase(MongoDb4TestConstants.DATABASE_NAME); assertNotNull(database); - final MongoCollection collection = - database.getCollection(getClass().getSimpleName()); + final String collectionName = getClass().getSimpleName(); + StatusLogger.getLogger().debug("Using collection name: {}", collectionName); + final MongoCollection collection = database.getCollection(collectionName); assertNotNull(collection); final Document first = collection.find().first(); assertNotNull(first); diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CollectionNameIT.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CollectionNameIT.java new file mode 100644 index 00000000000..f714ee2eb82 --- /dev/null +++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4CollectionNameIT.java @@ -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.mongodb4; + +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; + +@UsingMongoDb4 +@LoggerContextSource("MongoDb4CollectionNameIT.xml") +// Print debug status logger output upon failure +@UsingStatusListener +class MongoDb4CollectionNameIT extends AbstractMongoDb4CappedIT { + + @Test + @Override + protected void test(LoggerContext ctx, MongoClient mongoClient) { + super.test(ctx, mongoClient); + } +} diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4DatabaseAndCollectionNameIT.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4DatabaseAndCollectionNameIT.java new file mode 100644 index 00000000000..3c06692a64a --- /dev/null +++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4DatabaseAndCollectionNameIT.java @@ -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.mongodb4; + +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; + +@UsingMongoDb4 +@LoggerContextSource("MongoDb4DatabaseAndCollectionNameIT.xml") +// Print debug status logger output upon failure +@UsingStatusListener +class MongoDb4DatabaseAndCollectionNameIT extends AbstractMongoDb4CappedIT { + + @Test + @Override + protected void test(LoggerContext ctx, MongoClient mongoClient) { + super.test(ctx, mongoClient); + } +} diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4ProviderTest.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4ProviderTest.java new file mode 100644 index 00000000000..8588ead05ec --- /dev/null +++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4ProviderTest.java @@ -0,0 +1,116 @@ +/* + * 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.mongodb4; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import com.mongodb.MongoNamespace; +import com.mongodb.client.MongoCollection; +import java.lang.reflect.Field; +import org.bson.Document; +import org.junit.jupiter.api.Test; + +class MongoDb4ProviderTest { + + private static final String CON_STR_WO_DB = "mongodb://localhost:27017"; + + private static final String CON_STR_W_DB = "mongodb://localhost:27017/logging"; + + private static final String CON_STR_DB_COLL = "mongodb://localhost:27017/logging.logs"; + + private static final String COLLECTION_NAME = "logsTest"; + + private static final String DATABASE_NAME = "loggingTest"; + + @Test + void createProviderWithDatabaseAndCollectionProvidedViaConfig() { + MongoDb4Provider provider = MongoDb4Provider.newBuilder() + .setConnectionStringSource(CON_STR_WO_DB) + .setDatabaseName(DATABASE_NAME) + .setCollectionName(COLLECTION_NAME) + .build(); + assertThat(provider).isNotNull(); + assertProviderNamespace(provider, DATABASE_NAME, COLLECTION_NAME); + } + + @Test + void createProviderWithoutDatabaseName() { + assertThatThrownBy(() -> MongoDb4Provider.newBuilder() + .setConnectionStringSource(CON_STR_WO_DB) + .build()) + .hasMessage("Invalid MongoDB database name: `null`"); + } + + @Test + void createProviderWithoutDatabaseNameWithCollectionName() { + assertThatThrownBy(() -> MongoDb4Provider.newBuilder() + .setConnectionStringSource(CON_STR_WO_DB) + .setCollectionName(COLLECTION_NAME) + .build()) + .hasMessage("Invalid MongoDB database name: `null`"); + } + + @Test + void createProviderWithoutCollectionName() { + assertThatThrownBy(() -> MongoDb4Provider.newBuilder() + .setConnectionStringSource(CON_STR_WO_DB) + .setDatabaseName(DATABASE_NAME) + .build()) + .hasMessage("Invalid MongoDB collection name: `null`"); + } + + @Test + void createProviderWithDatabaseOnConnectionString() { + MongoDb4Provider provider = MongoDb4Provider.newBuilder() + .setConnectionStringSource(CON_STR_W_DB) + .setCollectionName(COLLECTION_NAME) + .build(); + assertThat(provider).isNotNull(); + assertProviderNamespace(provider, "logging", COLLECTION_NAME); + } + + @Test + void createProviderConfigOverridesConnectionString() { + MongoDb4Provider provider = MongoDb4Provider.newBuilder() + .setConnectionStringSource(CON_STR_DB_COLL) + .setCollectionName(COLLECTION_NAME) + .setDatabaseName(DATABASE_NAME) + .build(); + assertThat(provider).isNotNull(); + assertProviderNamespace(provider, DATABASE_NAME, COLLECTION_NAME); + } + + private static void assertProviderNamespace(MongoDb4Provider provider, String databaseName, String collectionName) { + MongoNamespace namespace = providerNamespace(provider); + assertThat(namespace.getDatabaseName()).isEqualTo(databaseName); + assertThat(namespace.getCollectionName()).isEqualTo(collectionName); + } + + private static MongoNamespace providerNamespace(MongoDb4Provider provider) { + try { + MongoDb4Connection connection = provider.getConnection(); + Field collectionField = MongoDb4Connection.class.getDeclaredField("collection"); + collectionField.setAccessible(true); + @SuppressWarnings("unchecked") + MongoCollection collection = (MongoCollection) collectionField.get(connection); + return collection.getNamespace(); + } catch (Exception exception) { + throw new RuntimeException(exception); + } + } +} diff --git a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Resolver.java b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Resolver.java index 0534c09631a..c4e1628db4b 100644 --- a/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Resolver.java +++ b/log4j-mongodb4/src/test/java/org/apache/logging/log4j/mongodb4/MongoDb4Resolver.java @@ -30,8 +30,6 @@ class MongoDb4Resolver extends TypeBasedParameterResolver implements BeforeAllCallback { - static final String PORT_PROPERTY = "log4j2.mongo.port"; - public MongoDb4Resolver() { super(MongoClient.class); } diff --git a/log4j-mongodb4/src/test/resources/MongoDb4CollectionNameIT.xml b/log4j-mongodb4/src/test/resources/MongoDb4CollectionNameIT.xml new file mode 100644 index 00000000000..09834dc526c --- /dev/null +++ b/log4j-mongodb4/src/test/resources/MongoDb4CollectionNameIT.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + diff --git a/log4j-mongodb4/src/test/resources/MongoDb4DatabaseAndCollectionNameIT.xml b/log4j-mongodb4/src/test/resources/MongoDb4DatabaseAndCollectionNameIT.xml new file mode 100644 index 00000000000..790c991ccf7 --- /dev/null +++ b/log4j-mongodb4/src/test/resources/MongoDb4DatabaseAndCollectionNameIT.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + diff --git a/log4j-parent/pom.xml b/log4j-parent/pom.xml index c429feaf95a..7b7ddeb8766 100644 --- a/log4j-parent/pom.xml +++ b/log4j-parent/pom.xml @@ -66,7 +66,8 @@ 3.27.3 4.2.2 2.0b6 - 3.11.18 + 7.1.0 + 3.11.19 3.11.5 1.17.1 1.27.1 @@ -125,8 +126,11 @@ 2.0.8 6.0.0 + 2.0.0 + 1.1.2 4.14.0 3.6.0 + 4.9.1 2.7.18 5.3.39 2.0.3 @@ -574,6 +578,12 @@ ${jna.version} + + org.jspecify + jspecify + ${jspecify.version} + + junit junit @@ -829,6 +839,7 @@ biz.aQute.bnd biz.aQute.bnd.annotation + ${bnd.annotation.version} provided @@ -841,19 +852,22 @@ org.osgi - osgi.annotation + org.osgi.annotation.bundle + ${osgi.annotation.bundle.version} provided org.osgi - org.osgi.annotation.bundle + org.osgi.annotation.versioning + ${osgi.annotation.versioning.version} provided com.github.spotbugs spotbugs-annotations + ${spotbugs-annotations.version} provided @@ -977,6 +991,19 @@ + + + org.apache.maven.plugins + maven-compiler-plugin + + + --should-stop=ifError=FLOW + + + + diff --git a/pom.xml b/pom.xml index bcc6f1b9c75..bb67727f5fe 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ org.apache.logging logging-parent - 11.3.0 + 12.0.0 @@ -357,6 +357,7 @@ + 1.0.0 0.9.0 21.7.1 10.5.0 @@ -370,7 +371,7 @@ ${maven.multiModuleProjectDirectory}/target/plugin-descriptors/phase1 ${maven.multiModuleProjectDirectory}/target/plugin-descriptors/phase2 - + 3.2.5 @@ -562,23 +563,6 @@ - - - org.codehaus.mojo - flatten-maven-plugin - ${flatten-maven-plugin.version} - - - flatten-bom - - flatten - - process-resources - false - - - - @@ -993,6 +977,7 @@ org.jspecify jspecify ${jspecify.version} + test diff --git a/src/changelog/.2.x.x/3011_http_appender_validation.xml b/src/changelog/.2.x.x/3011_http_appender_validation.xml new file mode 100644 index 00000000000..5038a378d17 --- /dev/null +++ b/src/changelog/.2.x.x/3011_http_appender_validation.xml @@ -0,0 +1,8 @@ + + + + Improves validation of HTTP Appender. + diff --git a/src/changelog/.2.x.x/3467_add_mongodb_conn_db_name.xml b/src/changelog/.2.x.x/3467_add_mongodb_conn_db_name.xml new file mode 100644 index 00000000000..ecf5d7e625b --- /dev/null +++ b/src/changelog/.2.x.x/3467_add_mongodb_conn_db_name.xml @@ -0,0 +1,8 @@ + + + + Add `collectionName` and `databaseName` arguments to the MongoDB appender + diff --git a/src/changelog/.2.x.x/update_org_apache_cassandra_cassandra_all.xml b/src/changelog/.2.x.x/update_org_apache_cassandra_cassandra_all.xml index 01c4737997c..40a9dcfbec6 100644 --- a/src/changelog/.2.x.x/update_org_apache_cassandra_cassandra_all.xml +++ b/src/changelog/.2.x.x/update_org_apache_cassandra_cassandra_all.xml @@ -3,6 +3,6 @@ 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="updated"> - - Update `org.apache.cassandra:cassandra-all` to version `3.11.18` + + Update `org.apache.cassandra:cassandra-all` to version `3.11.19` diff --git a/src/changelog/.2.x.x/update_org_apache_logging_logging_parent.xml b/src/changelog/.2.x.x/update_org_apache_logging_logging_parent.xml index 5b17082960b..0ea7b563939 100644 --- a/src/changelog/.2.x.x/update_org_apache_logging_logging_parent.xml +++ b/src/changelog/.2.x.x/update_org_apache_logging_logging_parent.xml @@ -3,5 +3,5 @@ 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="updated"> - Update `org.apache.logging:logging-parent` to version `11.3.0` + Update `org.apache.logging:logging-parent` to version `12.0.0` diff --git a/src/changelog/.2.x.x/update_org_mongodb_bson.xml b/src/changelog/.2.x.x/update_org_mongodb_bson.xml index 02f463185e0..ce86df17157 100644 --- a/src/changelog/.2.x.x/update_org_mongodb_bson.xml +++ b/src/changelog/.2.x.x/update_org_mongodb_bson.xml @@ -3,6 +3,6 @@ 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="updated"> - - Update `org.mongodb:bson` to version `4.11.5` + + Update `org.mongodb:bson` to version `5.3.1` diff --git a/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.json b/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.json index 14512de6346..3ebdb0994eb 100644 --- a/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.json +++ b/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.json @@ -6,9 +6,7 @@ "name": "SOCKET", "host": "localhost", "port": 12345, - "JsonTemplateLayout": { - "nullEventDelimiterEnabled": true - } + "JsonTemplateLayout": {} } // end::socketAppender[] }, diff --git a/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.properties b/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.properties index b3aa633b9f2..c25e660b87a 100644 --- a/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.properties +++ b/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.properties @@ -21,7 +21,6 @@ appender.0.name = SOCKET appender.0.host = localhost appender.0.port = 12345 appender.0.layout.type = JsonTemplateLayout -appender.0.layout.nullEventDelimiterEnabled = true # end::socketAppender[] rootLogger.level = WARN diff --git a/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.xml b/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.xml index bc7e6e3697e..13b960ec2b9 100644 --- a/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.xml +++ b/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.xml @@ -24,7 +24,7 @@ - + diff --git a/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.yaml b/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.yaml index 60cc47d586d..d6e0a44787c 100644 --- a/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.yaml +++ b/src/site/antora/modules/ROOT/examples/cloud/logstash/log4j2.yaml @@ -22,8 +22,7 @@ Configuration: name: "SOCKET" host: "localhost" port: 12345 - JsonTemplateLayout: - nullEventDelimiterEnabled: true + JsonTemplateLayout: {} # end::socketAppender[] Loggers: diff --git a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.json b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.json index 2b47690c0b5..702a4c3591c 100644 --- a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.json +++ b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.json @@ -5,7 +5,9 @@ "NoSql": { "name": "MONGO", "MongoDb": { - "connection": "mongodb://${env:DB_USER}:${env:DB_PASS}@localhost:27017/logging.logs" + "connection": "mongodb://${env:DB_USER}:${env:DB_PASS}@localhost:27017/", + "databaseName": "logging", + "collectionName": "logs" }, "KeyValuePair": [ { diff --git a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.properties b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.properties index e0e97ac2872..ba3112e8951 100644 --- a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.properties +++ b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.properties @@ -19,7 +19,9 @@ appender.0.type = NoSql appender.0.name = MONGO appender.0.provider.type = MongoDB -appender.0.provider.connection = mongodb://${env:DB_USER}:${env:DB_PASS}@localhost:27017/logging.logs +appender.0.provider.connection = mongodb://${env:DB_USER}:${env:DB_PASS}@localhost:27017 +appender.0.provider.databaseName = logging +appender.0.provider.collectionName = logs appender.0.kv[0].type = KeyValuePair appender.0.kv[0].key = startTime diff --git a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.xml b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.xml index cd9f458ac3a..fc4e3b06972 100644 --- a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.xml +++ b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.xml @@ -23,7 +23,9 @@ - + diff --git a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.yaml b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.yaml index 2cb5df2c85f..1b286eec629 100644 --- a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.yaml +++ b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo-keys.yaml @@ -20,7 +20,9 @@ Configuration: NoSql: name: "MONGO" MongoDb: - connection: "mongodb://${env:DB_USER}:${env:DB_PASS}@localhost:27017/logging.logs" + connection: "mongodb://${env:DB_USER}:${env:DB_PASS}@localhost:27017/" + databaseName: "logging" + collectionName: "logs" KeyValuePair: - key: "startTime" value: "${date:yyyy-MM-dd hh:mm:ss.SSS}" # <1> diff --git a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.json b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.json index d06b3a190f6..b8bd82389e6 100644 --- a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.json +++ b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.json @@ -10,7 +10,9 @@ "NoSql": { "name": "MONGO", "MongoDb": { - "connection": "mongodb://${env:DB_USER}:${env:DB_PASS}@localhost:27017/logging.logs" + "connection": "mongodb://${env:DB_USER}:${env:DB_PASS}@localhost:27017/", + "databaseName": "logging", + "collectionName": "logs" } } // end::appender[] diff --git a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.properties b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.properties index 6a1e188310c..ab06837d8b9 100644 --- a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.properties +++ b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.properties @@ -22,7 +22,9 @@ appender.0.layout.type = JsonTemplateLayout appender.1.type = NoSql appender.1.name = MONGO appender.1.provider.type = MongoDB -appender.1.provider.connection = mongodb://${env:DB_USER}:${env:DB_PASS}@localhost:27017/logging.logs +appender.1.provider.connection = mongodb://${env:DB_USER}:${env:DB_PASS}@localhost:27017/ +appender.1.provider.databaseName = logging +appender.1.provider.collectionName = logs # end::appender[] # tag::loggers[] rootLogger.level = INFO diff --git a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.xml b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.xml index 31fe89f2f19..d5a22a1134b 100644 --- a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.xml +++ b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.xml @@ -27,7 +27,9 @@ - + diff --git a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.yaml b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.yaml index f5bd4b66121..86874f8d1a6 100644 --- a/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.yaml +++ b/src/site/antora/modules/ROOT/examples/manual/appenders/database/nosql-mongo.yaml @@ -24,7 +24,9 @@ Configuration: NoSql: name: "MONGO" MongoDb: - connection: "mongodb://${env:DB_USER}:${env:DB_PASS}@localhost:27017/logging.logs" + connection: "mongodb://${env:DB_USER}:${env:DB_PASS}@localhost:27017/" + databaseName: "logging" + collectionName: "logs" # end::appender[] Loggers: # tag::loggers[] diff --git a/src/site/antora/modules/ROOT/pages/manual/appenders/database.adoc b/src/site/antora/modules/ROOT/pages/manual/appenders/database.adoc index cf42f454d9a..901c37ba25a 100644 --- a/src/site/antora/modules/ROOT/pages/manual/appenders/database.adoc +++ b/src/site/antora/modules/ROOT/pages/manual/appenders/database.adoc @@ -1164,14 +1164,32 @@ It supports the following configuration options: | Attribute | Type | Default value | Description | [[MongoDbProvider-attr-connection]]connection -| https://mongodb.github.io/mongo-java-driver/5.1/apidocs/mongodb-driver-core/com/mongodb/ConnectionString.html[`ConnectionString`] +| https://www.mongodb.com/docs/manual/reference/connection-string/#standard-connection-string-format[Connection String] | | It specifies the connection URI used to reach the server. -See -https://www.mongodb.com/docs/drivers/java/sync/current/fundamentals/connection/connect/#connection-uri[Connection URI documentation] -for its format. +**Required** + +| [[MongoDbProvider-attr-databaseName]]databaseName +| `string` +| +| +It specifies the name of the database for the appender to use. + +The database name can also be specified in <>. +If both are provided, this `databaseName` attribute will be used. + +**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 <> per https://mongodb.github.io/mongo-java-driver/5.3/apidocs/mongodb-driver-core/com/mongodb/ConnectionString.html[`ConnectionString` of the MongoDB Java Driver]. +If both are provided, this `collectionName` attribute will be used. **Required** @@ -1210,15 +1228,11 @@ It supports the following configuration attributes: | Attribute | Type | Default value | Description | [[MongoDb4Provider-attr-connection]]connection -| https://mongodb.github.io/mongo-java-driver/5.1/apidocs/mongodb-driver-core/com/mongodb/ConnectionString.html[`ConnectionString`] +| https://mongodb.github.io/mongo-java-driver/5.3/apidocs/mongodb-driver-core/com/mongodb/ConnectionString.html[`ConnectionString`] | | It specifies the connection URI used to reach the server. -See -https://www.mongodb.com/docs/drivers/java/sync/current/fundamentals/connection/connect/#connection-uri[Connection URI documentation] -for its format. - **Required** | [[MongoDb4Provider-attr-capped]]capped diff --git a/src/site/antora/modules/ROOT/pages/soa.adoc b/src/site/antora/modules/ROOT/pages/soa.adoc index 5db72c82478..063909ae495 100644 --- a/src/site/antora/modules/ROOT/pages/soa.adoc +++ b/src/site/antora/modules/ROOT/pages/soa.adoc @@ -99,8 +99,7 @@ Nevertheless, there are some tips we recommend you to practice: * *For writing to console*, use a xref:manual/appenders.adoc#ConsoleAppender[Console Appender] and make sure to configure its `direct` attribute to `true` for the maximum efficiency. -* *For writing to an external service*, use a xref:manual/appenders/network.adoc#SocketAppender[Socket Appender] and make sure to set the protocol to TCP and configure the null delimiter of the associated layout. -For instance, see xref:manual/json-template-layout.adoc#plugin-attr-nullEventDelimiterEnabled[the `nullEventDelimiterEnabled` configuration attribute of JSON Template Layout]. +* *For writing to an external service*, use a xref:manual/appenders/network.adoc#SocketAppender[Socket Appender] and make sure to configure the protocol and layout's null termination (e.g., see xref:manual/json-template-layout.adoc#plugin-attr-nullEventDelimiterEnabled[the `nullEventDelimiterEnabled` configuration attribute of JSON Template Layout]) appropriately. [#file] === Avoid writing to files