-
Notifications
You must be signed in to change notification settings - Fork 14.7k
KAFKA-9366: Upgrade log4j to log4j2 #17373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is the initial version. I'd like to run it on CI first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this @frankvicky.
Is it really necessary to rename the log4j config files? The KIP mentions a system property that allows us to load log4j.properties files https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=158870552#KIP653:Upgradelog4jtolog4j2-Compatibility,Deprecation,andMigrationPlan
I could understand migrating our internal log4j configs for tests and such, but I think we should avoid forcing a change in our production configs.
I also see that this page mentions a log4j to log4j2 bridge https://logging.apache.org/log4j/2.x/migrate-from-log4j1.html. Would that help us at all?
build.gradle
Outdated
testRuntimeOnly libs.slf4jLog4j2 | ||
testRuntimeOnly libs.junitPlatformLanucher |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These (and other similar testRuntimeOnly
) should be put into the runtimeTestLibs
definition
build.gradle
Outdated
implementation libs.slf4jApi | ||
implementation libs.jacksonAnnotations | ||
implementation libs.jacksonDatabind | ||
implementation libs.bndlib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this dependency for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mumrah
I add this to fix the warning during build:
/home/frankvicky/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.24.1/7ebeb12c20606373005af4232cd0ecca72613dda/log4j-api-2.24.1.jar(/org/apache/logging/log4j/Level.class): warning: Cannot find annotation method 'value()' in type 'BaselineIgnore': class file for aQute.bnd.annotation.baseline.BaselineIgnore not found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced we need that dependency. Also it seems to complain about an annotation so at least we should not need it at runtime, so we should not include it in our distribution package. Currently it's included in the artifact generated by releaseTarGz
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, I will try to solve this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The BND annotations are intentionally in the provided
Maven scope of all Log4j artifacts, so that these annotations with CLASS
retention do not end up in the runtime classpath. You can do the same and add them as compileOnly
in Gradle.
The compiler warnings should disappear once JDK-8342833 is fixed.
Untile then we will remove the outdated ones (see apache/logging-log4j2#3133) in the next Log4j release, which should remove the warning on Level
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the information.
I have already changed its scope to compile time.
PTAL 😄
base_dir=$(dirname $0) | ||
|
||
if [ "x$KAFKA_LOG4J_OPTS" = "x" ]; then | ||
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/../config/log4j.properties" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could break some existing Kafka installations. If users are extracting in place or copying previous config files to a new installation directory, they will be expecting the log4j.properties to still work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The switch from the legacy to the new configuration format can be based on the presence of specific files:
if [ -f "$base_dir/../config/log4j.properties" ]; then
echo DEPRECATED: Using Log4j 1.x configuration file \$KAFKA_HOME/config/log4j.properties >&2
echo To use a Log4j 2.x configuration, create a \$KAFKA_HOME/config/log4j2.xml file and remove the Log4j 1.x configration. >&2
echo See https://logging.apache.org/log4j/2.x/migrate-from-log4j1.html#Log4j2ConfigurationFormat for details about Log4j configuration file migration. >&2
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/../config/log4j.properties"
elif [ -f "$base_dir/../config/log4j2.xml" ]; then
export KAFKA_LOG4J_OPTS="-Dlog4j2.configurationFile=$base_dir/../config/log4j2.xml"
fi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure why we override the KAFKA_LOG4J_OPTS
here. We typically allow users to define custom KAFKA_LOG4J_OPTS
. Moreover, overriding KAFKA_LOG4J_OPTS
can break many end-to-end tests, as they often create log4j configurations dynamically and pass them through KAFKA_LOG4J_OPTS
Noted that we do not require users to strictly use the path $base_dir/../config/log4j2.xml
.
Hello @mumrah |
0ecc326
to
9fc1203
Compare
0c1e6bf
to
4b722a5
Compare
4b722a5
to
7200b43
Compare
revert unnecessary change
@frankvicky Could you please open minor to address following items?
|
Interesting. This one fails consistently on our infra (and succeeds without this change). I wonder if there is some different test configuration that causes the issue. |
This reverts commit b37b89c.
There are many tests which are failed quickly.
It can pass the check of |
@chia7712 sure. I will run it and post the results |
This pull request replaces Log4j with Log4j2 across the entire project, including dependencies, configurations, and code. The notable changes are listed below: 1. Introduce Log4j2 Instead of Log4j 2. Change Configuration File Format from Properties to YAML 3. Adds warnings to notify users if they are still using Log4j properties, encouraging them to transition to Log4j2 configurations Co-authored-by: Lee Dongjin <[email protected]> Reviewers: Luke Chen <[email protected]>, Mickael Maison <[email protected]>, Chia-Ping Tsai <[email protected]>
This PR breaks downstream project that depends on kafka_2.13 and reload4j because there is clashing in class LoggingEvent, which exists in
|
You can not have both |
The point is that kafka was including |
I assume the scenario you describe is to add "kafka_2.13" as dependency for the downstream project. The log4j2 are declared as "implementation" in core module, so downstream project should not "include" log4j2 in the dependencies automatically. not sure why |
@trnguyencflt thanks for your report. I'd like to reduce the gap of upgrading to kafka 4.0 as much as possible, so please share the details to me |
@chia7712 we include kafka_2.13 as dependency via maven https://github.com/confluentinc/kafka-rest/blob/d6405f714e0e453d6eb5b9a496faac4202c89cab/kafka-rest/pom.xml#L42, and it brings log4j-1.2-api as a runtime dependency (below is from mvn dependency:tree)
|
@trnguyencflt thanks for your response. this is the pom file with above approach and there is not
By contrast,
|
Hi @trnguyencflt |
@trnguyencflt we have resolved the issue in #18472. If you have some free time, could you please test it on your project? |
…ing kafka JIRA: KAFKA-18752 In KAFKA-18466 we remove the slf4j impl from runtime scope to fix the compatible issue (see apache#17373 (comment)). However, that also causes a side effect that in running some tasks slf4k can't find any provider as they are included to "release-only" We could fix this by adding releasOnly to class path
…ing kafka JIRA: KAFKA-18752 In KAFKA-18466 we remove the slf4j impl from runtime scope to fix the compatible issue (see apache#17373 (comment)). However, that also causes a side effect that in running some tasks slf4k can't find any provider as they are included to "release-only" We could fix this by adding releasOnly to class path
…ing kafka JIRA: KAFKA-18752 In KAFKA-18466 we remove the slf4j impl from runtime scope to fix the compatible issue (see apache#17373 (comment)). However, that also causes a side effect that in running some tasks slf4k can't find any provider as they are included to "release-only" We could fix this by adding releasOnly to class path
…ing kafka JIRA: KAFKA-18752 In KAFKA-18466 we remove the slf4j impl from runtime scope to fix the compatible issue (see apache#17373 (comment)). However, that also causes a side effect that in running some tasks slf4k can't find any provider as they are included to "release-only" We could fix this by adding releasOnly to class path
…ing kafka JIRA: KAFKA-18752 In KAFKA-18466 we remove the slf4j impl from runtime scope to fix the compatible issue (see apache#17373 (comment)). However, that also causes a side effect that in running some tasks slf4k can't find any provider as they are included to "release-only" We could fix this by adding releasOnly to class path
…ing kafka JIRA: KAFKA-18752 In KAFKA-18466 we remove the slf4j impl from runtime scope to fix the compatible issue (see apache#17373 (comment)). However, that also causes a side effect that in running some tasks slf4k can't find any provider as they are included to "release-only" We could fix this by adding releasOnly to class path
JIRA: KAFKA-9366
Committer Checklist (excluded from commit message)