From 86c5477e8163f9975434c62ccec2b46b762cd6c7 Mon Sep 17 00:00:00 2001 From: Piotr Przybylski Date: Sun, 6 Sep 2026 23:06:30 +0200 Subject: [PATCH] [FLINK-40574][build] Update SLF4J from 1.7.36 to 2.0.19 Generated-by: Claude Code (Opus 5) --- .../docs/deployment/advanced/logging.md | 28 ++++++++++++------- .../docs/dev/configuration/overview.md | 4 +-- .../docs/deployment/advanced/logging.md | 24 ++++++++++------ .../docs/dev/configuration/overview.md | 4 +-- .../util/MdcLogbackCompatibilityTest.java | 11 ++++---- flink-dist/pom.xml | 2 +- flink-dist/src/main/assemblies/bin.xml | 2 +- flink-dist/src/main/resources/META-INF/NOTICE | 2 +- flink-docs/pom.xml | 2 +- .../flink-end-to-end-tests-table-api/pom.xml | 2 +- flink-examples/pom.xml | 2 +- .../src/main/resources/META-INF/NOTICE | 2 +- .../resources/archetype-resources/pom.xml | 2 +- .../flink-test-utils-junit/pom.xml | 2 +- .../resources/archetype-resources/pom.xml | 2 +- .../resources/archetype-resources/pom.xml | 2 +- pom.xml | 8 +++--- tools/ci/flink-ci-tools/pom.xml | 2 +- tools/releasing/NOTICE-binary_PREAMBLE.txt | 2 +- 19 files changed, 59 insertions(+), 46 deletions(-) diff --git a/docs/content.zh/docs/deployment/advanced/logging.md b/docs/content.zh/docs/deployment/advanced/logging.md index 2e1f23d201c98..9cb628fa7c756 100644 --- a/docs/content.zh/docs/deployment/advanced/logging.md +++ b/docs/content.zh/docs/deployment/advanced/logging.md @@ -91,31 +91,39 @@ Flink 附带了 [Log4j API bridge](https://logging.apache.org/log4j/log4j-2.2/lo -## 配置 Log4j1 +## 配置 Log4j 1 (reload4j) -要将 Flink 与 [Log4j 1](https://logging.apache.org/log4j/1.2/) 一起使用,必须确保: -- Classpath 中不存在 `org.apache.logging.log4j:log4j-core`、`org.apache.logging.log4j:log4j-slf4j-impl` 和 `org.apache.logging.log4j:log4j-1.2-api`; -- 且 Classpath 中存在 `log4j:log4j`、`org.slf4j:slf4j-log4j12`、`org.apache.logging.log4j:log4j-to-slf4j` 和 `org.apache.logging.log4j:log4j-api`。 +要将 Flink 与 [reload4j](https://reload4j.qos.ch/) 一起使用,必须确保: +- Classpath 中不存在 `org.apache.logging.log4j:log4j-core`、`org.apache.logging.log4j:log4j-slf4j2-impl` 和 `org.apache.logging.log4j:log4j-1.2-api`; +- 且 Classpath 中存在 `ch.qos.reload4j:reload4j`、`org.slf4j:slf4j-reload4j`、`org.apache.logging.log4j:log4j-to-slf4j` 和 `org.apache.logging.log4j:log4j-api`。 -如果在 IDE 中使用 Log4j 1,则必须在 pom 文件中使用上述 Classpath 中应该存在的 jars 依赖项来替换 Classpath 中不应该存在的 jars 依赖项,并尽可能的排除那些传递依赖于 Classpath 中不存在 jars 的依赖项。 +如果在 IDE 中使用 reload4j,则必须在 pom 文件中使用上述 Classpath 中应该存在的 jars 依赖项来替换 Classpath 中不应该存在的 jars 依赖项,并尽可能的排除那些传递依赖于 Classpath 中不存在 jars 的依赖项。 对于 Flink 发行版,这意味着你必须 -- 从 `lib` 目录中移除 `log4j-core`,`log4j-slf4j-impl` 和 `log4j-1.2-api` jars; -- 往 `lib` 目录中添加 `log4j`,`slf4j-log4j12` 和 `log4j-to-slf4j` jars; +- 从 `lib` 目录中移除 `log4j-core`,`log4j-slf4j2-impl` 和 `log4j-1.2-api` jars; +- 往 `lib` 目录中添加 `reload4j`,`slf4j-reload4j` 和 `log4j-to-slf4j` jars; - 用适配的 Log4j1 版本替换 `conf` 目录中的所有 log4j 配置文件。 +{{< hint warning >}} + +[Reload4j](https://reload4j.qos.ch/) 是 Log4j 1.2.17 的一个持续维护的分支,保留了 `org.apache.log4j` 类和 Log4j 1 的配置格式。 +不能使用原来的 `log4j:log4j`,因为它的 SLF4J binding(`org.slf4j:slf4j-log4j12`)只适用于 SLF4J 1.7,Flink 自带的 SLF4J 2 会直接忽略它。 +请使用与 Flink 的 `slf4j-api`(2.x)版本一致的 `org.slf4j:slf4j-reload4j`。 + +{{< /hint >}} + ## 配置 logback 要将 Flink 与 [logback](https://logback.qos.ch/) 一起使用,必须确保: -- Classpath 中不存在 `org.apache.logging.log4j:log4j-slf4j-impl`; +- Classpath 中不存在 `org.apache.logging.log4j:log4j-slf4j2-impl`; - Classpath 中存在 `ch.qos.logback:logback-core` 和 `ch.qos.logback:logback-classic`。 如果在 IDE 中使用 logback,则必须在 pom 文件中使用上述 Classpath 中应该存在的 jars 依赖项来替换 Classpath 中不应该存在的 jars 依赖项,并尽可能的排除那些传递依赖于 Classpath 中不存在 jars 的依赖项。 对于 Flink 发行版,这意味着你必须 -- 从 `lib` 目录中移除 `log4j-slf4j-impl` jars; +- 从 `lib` 目录中移除 `log4j-slf4j2-impl` jars; - 向 `lib` 目录中添加 `logback-core` 和 `logback-classic` jars。 Flink 发行版在 `conf` 目录中附带了以下 logback 配置文件,如果启用了 logback,则会自动使用这些文件: @@ -125,7 +133,7 @@ Flink 发行版在 `conf` 目录中附带了以下 logback 配置文件,如果 {{< hint warning >}} -Logback 1.3+ 需要 SLF4J 2,目前不支持。 +Flink 使用 SLF4J 2,因此需要 logback 1.3 或更高版本。 {{< /hint >}} diff --git a/docs/content.zh/docs/dev/configuration/overview.md b/docs/content.zh/docs/dev/configuration/overview.md index e0930a237ac91..23c9a5ae89c16 100644 --- a/docs/content.zh/docs/dev/configuration/overview.md +++ b/docs/content.zh/docs/dev/configuration/overview.md @@ -101,7 +101,7 @@ ext { javaVersion = '1.8' flinkVersion = '{{< version >}}' scalaBinaryVersion = '{{< scala_version >}}' - slf4jVersion = '1.7.36' + slf4jVersion = '2.0.19' log4jVersion = '2.26.1' } sourceCompatibility = javaVersion @@ -146,7 +146,7 @@ dependencies { // connectors. These must be in the flinkShadowJar configuration! // -------------------------------------------------------------- //flinkShadowJar "org.apache.flink:flink-connector-kafka:${flinkVersion}" - runtimeOnly "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}" + runtimeOnly "org.apache.logging.log4j:log4j-slf4j2-impl:${log4jVersion}" runtimeOnly "org.apache.logging.log4j:log4j-api:${log4jVersion}" runtimeOnly "org.apache.logging.log4j:log4j-core:${log4jVersion}" // Add test dependencies here. diff --git a/docs/content/docs/deployment/advanced/logging.md b/docs/content/docs/deployment/advanced/logging.md index 82c8e6f77524d..b53e5dc5b3606 100644 --- a/docs/content/docs/deployment/advanced/logging.md +++ b/docs/content/docs/deployment/advanced/logging.md @@ -98,29 +98,35 @@ Flink ships with the [Log4j API bridge](https://logging.apache.org/log4j/log4j-2 If you have custom Log4j 1 properties files or code that relies on Log4j 1, please check out the official Log4j [compatibility](https://logging.apache.org/log4j/2.x/manual/compatibility.html) and [migration](https://logging.apache.org/log4j/2.x/manual/migration.html) guides. -## Configuring Log4j1 +## Configuring Log4j 1 (reload4j) -To use Flink with [Log4j 1](https://logging.apache.org/log4j/1.2/) you must ensure that: -- `org.apache.logging.log4j:log4j-core`, `org.apache.logging.log4j:log4j-slf4j-impl` and `org.apache.logging.log4j:log4j-1.2-api` are not on the classpath, -- `log4j:log4j`, `org.slf4j:slf4j-log4j12`, `org.apache.logging.log4j:log4j-to-slf4j` and `org.apache.logging.log4j:log4j-api` are on the classpath. +To use Flink with [reload4j](https://reload4j.qos.ch/) you must ensure that: +- `org.apache.logging.log4j:log4j-core`, `org.apache.logging.log4j:log4j-slf4j2-impl` and `org.apache.logging.log4j:log4j-1.2-api` are not on the classpath, +- `ch.qos.reload4j:reload4j`, `org.slf4j:slf4j-reload4j`, `org.apache.logging.log4j:log4j-to-slf4j` and `org.apache.logging.log4j:log4j-api` are on the classpath. In the IDE this means you have to replace such dependencies defined in your pom, and possibly add exclusions on dependencies that transitively depend on them. For Flink distributions this means you have to -- remove the `log4j-core`, `log4j-slf4j-impl` and `log4j-1.2-api` jars from the `lib` directory, -- add the `log4j`, `slf4j-log4j12` and `log4j-to-slf4j` jars to the `lib` directory, +- remove the `log4j-core`, `log4j-slf4j2-impl` and `log4j-1.2-api` jars from the `lib` directory, +- add the `reload4j`, `slf4j-reload4j` and `log4j-to-slf4j` jars to the `lib` directory, - replace all log4j properties files in the `conf` directory with Log4j1-compliant versions. +{{< hint warning >}} +[Reload4j](https://reload4j.qos.ch/) is a maintained fork of Log4j 1.2.17; it keeps the `org.apache.log4j` classes and the Log4j 1 configuration format. +The original `log4j:log4j` artifact cannot be used, because its SLF4J binding (`org.slf4j:slf4j-log4j12`) exists for SLF4J 1.7 only and is ignored by the SLF4J 2 version Flink ships with. +Use an `org.slf4j:slf4j-reload4j` version matching Flink's `slf4j-api` (2.x). +{{< /hint >}} + ## Configuring logback To use Flink with [logback](https://logback.qos.ch/) you must ensure that: -- `org.apache.logging.log4j:log4j-slf4j-impl` is not on the classpath, +- `org.apache.logging.log4j:log4j-slf4j2-impl` is not on the classpath, - `ch.qos.logback:logback-core` and `ch.qos.logback:logback-classic` are on the classpath. In the IDE this means you have to replace such dependencies defined in your pom, and possibly add exclusions on dependencies that transitively depend on them. For Flink distributions this means you have to -- remove the `log4j-slf4j-impl` jar from the `lib` directory, +- remove the `log4j-slf4j2-impl` jar from the `lib` directory, - add the `logback-core`, and `logback-classic` jars to the `lib` directory. The Flink distribution ships with the following logback configuration files in the `conf` directory, which are used automatically if logback is enabled: @@ -129,7 +135,7 @@ The Flink distribution ships with the following logback configuration files in t - `logback.xml`: used for command line interface and Job-/TaskManagers by default {{< hint warning >}} -Logback 1.3+ requires SLF4J 2, which is currently not supported. +Flink uses SLF4J 2, which requires logback 1.3 or later. {{< /hint >}} ## Best practices for developers diff --git a/docs/content/docs/dev/configuration/overview.md b/docs/content/docs/dev/configuration/overview.md index 730b5bb925556..f88b34da36b8e 100644 --- a/docs/content/docs/dev/configuration/overview.md +++ b/docs/content/docs/dev/configuration/overview.md @@ -103,7 +103,7 @@ ext { javaVersion = '1.8' flinkVersion = '{{< version >}}' scalaBinaryVersion = '{{< scala_version >}}' - slf4jVersion = '1.7.36' + slf4jVersion = '2.0.19' log4jVersion = '2.26.1' } sourceCompatibility = javaVersion @@ -148,7 +148,7 @@ dependencies { // connectors. These must be in the flinkShadowJar configuration! // -------------------------------------------------------------- //flinkShadowJar "org.apache.flink:flink-connector-kafka:${flinkVersion}" - runtimeOnly "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}" + runtimeOnly "org.apache.logging.log4j:log4j-slf4j2-impl:${log4jVersion}" runtimeOnly "org.apache.logging.log4j:log4j-api:${log4jVersion}" runtimeOnly "org.apache.logging.log4j:log4j-core:${log4jVersion}" // Add test dependencies here. diff --git a/flink-core/src/test/java/org/apache/flink/util/MdcLogbackCompatibilityTest.java b/flink-core/src/test/java/org/apache/flink/util/MdcLogbackCompatibilityTest.java index 5cef556455141..ea7458c0725bf 100644 --- a/flink-core/src/test/java/org/apache/flink/util/MdcLogbackCompatibilityTest.java +++ b/flink-core/src/test/java/org/apache/flink/util/MdcLogbackCompatibilityTest.java @@ -50,10 +50,9 @@ void tearDown() throws Exception { } /** - * The {@link MDC#setContextMap(Map)} method in Logback 1.2 does not accept nulls, unlike Log4j - * and Logback 1.3.2. BasicMDCAdapter is used to replicate this behavior for testing without - * bundling Logback into flink-core. See https://issues.apache.org/jira/browse/FLINK-36227 for - * details. + * Restoring an absent (null) MDC context must not fail, regardless of the backend in use. + * Historically, {@link MDC#setContextMap(Map)} in Logback 1.2 rejected nulls, unlike Log4j and + * Logback 1.3.2 (see https://issues.apache.org/jira/browse/FLINK-36227). */ @Test void testContextRestorationWorksWithNullContext() { @@ -67,13 +66,13 @@ void testContextRestorationWorksWithNullContext() { } private MDCAdapter getCurrentMDCAdapter() throws Exception { - Field adapterField = MDC.class.getDeclaredField("mdcAdapter"); + Field adapterField = MDC.class.getDeclaredField("MDC_ADAPTER"); adapterField.setAccessible(true); return (MDCAdapter) adapterField.get(null); } private void setMDCAdapter(MDCAdapter adapter) throws Exception { - Field adapterField = MDC.class.getDeclaredField("mdcAdapter"); + Field adapterField = MDC.class.getDeclaredField("MDC_ADAPTER"); adapterField.setAccessible(true); adapterField.set(null, adapter); } diff --git a/flink-dist/pom.xml b/flink-dist/pom.xml index 5dc15a3d1af95..5e469968478e0 100644 --- a/flink-dist/pom.xml +++ b/flink-dist/pom.xml @@ -167,7 +167,7 @@ under the License. org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl compile diff --git a/flink-dist/src/main/assemblies/bin.xml b/flink-dist/src/main/assemblies/bin.xml index ea855a0a4c1b3..1334f66ba6298 100644 --- a/flink-dist/src/main/assemblies/bin.xml +++ b/flink-dist/src/main/assemblies/bin.xml @@ -40,7 +40,7 @@ under the License. org.apache.logging.log4j:log4j-api org.apache.logging.log4j:log4j-core - org.apache.logging.log4j:log4j-slf4j-impl + org.apache.logging.log4j:log4j-slf4j2-impl org.apache.logging.log4j:log4j-1.2-api org.apache.logging.log4j:log4j-layout-template-json diff --git a/flink-dist/src/main/resources/META-INF/NOTICE b/flink-dist/src/main/resources/META-INF/NOTICE index ffeb7c67ee3db..03a6cfb5e6c83 100644 --- a/flink-dist/src/main/resources/META-INF/NOTICE +++ b/flink-dist/src/main/resources/META-INF/NOTICE @@ -34,7 +34,7 @@ See bundled license files for details. This project bundles the following dependencies under the MIT/X11 license. See bundled license files for details. -- org.slf4j:slf4j-api:1.7.36 +- org.slf4j:slf4j-api:2.0.19 This project bundles the following dependencies under the CDDL 1.1 license. See bundled license files for details. diff --git a/flink-docs/pom.xml b/flink-docs/pom.xml index 7f1e32f65bc43..e61014e0c9175 100644 --- a/flink-docs/pom.xml +++ b/flink-docs/pom.xml @@ -153,7 +153,7 @@ under the License. org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl compile diff --git a/flink-end-to-end-tests/flink-end-to-end-tests-table-api/pom.xml b/flink-end-to-end-tests/flink-end-to-end-tests-table-api/pom.xml index d7e88114adf44..b9ac5f3635077 100644 --- a/flink-end-to-end-tests/flink-end-to-end-tests-table-api/pom.xml +++ b/flink-end-to-end-tests/flink-end-to-end-tests-table-api/pom.xml @@ -79,7 +79,7 @@ under the License. org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl ${log4j.version} diff --git a/flink-examples/pom.xml b/flink-examples/pom.xml index 87e9555167da2..b1ea883738e73 100644 --- a/flink-examples/pom.xml +++ b/flink-examples/pom.xml @@ -56,7 +56,7 @@ under the License. org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl compile diff --git a/flink-python/src/main/resources/META-INF/NOTICE b/flink-python/src/main/resources/META-INF/NOTICE index c7b30e05a80ca..1bbf4ee038258 100644 --- a/flink-python/src/main/resources/META-INF/NOTICE +++ b/flink-python/src/main/resources/META-INF/NOTICE @@ -46,7 +46,7 @@ See bundled license files for details. - net.razorvine:pyrolite:4.13 - org.checkerframework:checker-qual:3.42.0 - io.github.classgraph:classgraph:4.8.162 -- org.slf4j:slf4j-api:1.7.36 +- org.slf4j:slf4j-api:2.0.19 - args4j:args4j:2.33 The bundled Apache Beam dependencies bundle the following dependencies under the Apache Software License 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt) diff --git a/flink-quickstart/flink-quickstart-java/src/main/resources/archetype-resources/pom.xml b/flink-quickstart/flink-quickstart-java/src/main/resources/archetype-resources/pom.xml index 235c104ac8160..da0fb142016bb 100644 --- a/flink-quickstart/flink-quickstart-java/src/main/resources/archetype-resources/pom.xml +++ b/flink-quickstart/flink-quickstart-java/src/main/resources/archetype-resources/pom.xml @@ -82,7 +82,7 @@ under the License. org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl ${log4j.version} runtime diff --git a/flink-test-utils-parent/flink-test-utils-junit/pom.xml b/flink-test-utils-parent/flink-test-utils-junit/pom.xml index ba8ec04743d77..f1398b1247ff3 100644 --- a/flink-test-utils-parent/flink-test-utils-junit/pom.xml +++ b/flink-test-utils-parent/flink-test-utils-junit/pom.xml @@ -54,7 +54,7 @@ under the License. org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl compile diff --git a/flink-walkthroughs/flink-walkthrough-datastream-java/src/main/resources/archetype-resources/pom.xml b/flink-walkthroughs/flink-walkthrough-datastream-java/src/main/resources/archetype-resources/pom.xml index 2ae8fa6067132..e8f7e42daf5a1 100644 --- a/flink-walkthroughs/flink-walkthrough-datastream-java/src/main/resources/archetype-resources/pom.xml +++ b/flink-walkthroughs/flink-walkthrough-datastream-java/src/main/resources/archetype-resources/pom.xml @@ -93,7 +93,7 @@ under the License. org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl ${log4j.version} runtime diff --git a/flink-walkthroughs/flink-walkthrough-table-java/src/main/resources/archetype-resources/pom.xml b/flink-walkthroughs/flink-walkthrough-table-java/src/main/resources/archetype-resources/pom.xml index d4eb3cb24675a..e7c7869d708f4 100644 --- a/flink-walkthroughs/flink-walkthrough-table-java/src/main/resources/archetype-resources/pom.xml +++ b/flink-walkthroughs/flink-walkthrough-table-java/src/main/resources/archetype-resources/pom.xml @@ -82,7 +82,7 @@ under the License. org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl ${log4j.version} runtime diff --git a/pom.xml b/pom.xml index c43256ffd6a8b..e95f33d247208 100644 --- a/pom.xml +++ b/pom.xml @@ -133,7 +133,7 @@ under the License. true 11 17 - 1.7.36 + 2.0.19 2.26.1 - org.apache.logging.log4j:log4j-slf4j-impl + org.apache.logging.log4j:log4j-slf4j2-impl org.apache.logging.log4j:log4j-api org.apache.logging.log4j:log4j-core org.apache.logging.log4j:log4j-1.2-api diff --git a/tools/ci/flink-ci-tools/pom.xml b/tools/ci/flink-ci-tools/pom.xml index 0a6677170f898..449a347d88c09 100644 --- a/tools/ci/flink-ci-tools/pom.xml +++ b/tools/ci/flink-ci-tools/pom.xml @@ -55,7 +55,7 @@ under the License. org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl compile diff --git a/tools/releasing/NOTICE-binary_PREAMBLE.txt b/tools/releasing/NOTICE-binary_PREAMBLE.txt index 46c43e8c32bff..7ea6c537132ab 100644 --- a/tools/releasing/NOTICE-binary_PREAMBLE.txt +++ b/tools/releasing/NOTICE-binary_PREAMBLE.txt @@ -10,7 +10,7 @@ This project bundles the following dependencies under the Apache Software Licens - org.apache.logging.log4j:log4j-api:2.26.1 - org.apache.logging.log4j:log4j-core:2.26.1 -- org.apache.logging.log4j:log4j-slf4j-impl:2.26.1 +- org.apache.logging.log4j:log4j-slf4j2-impl:2.26.1 - org.apache.logging.log4j:log4j-1.2-api:2.26.1 - org.apache.logging.log4j:log4j-layout-template-json:2.26.1