-
Notifications
You must be signed in to change notification settings - Fork 864
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
Introduce SLF4J for logging #3285
Conversation
66e19dc
to
cd9b7e0
Compare
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 🙏
I haven't gotten through the whole PR but a couple questions.
Also did you miss
./acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java:84 ?
config/src/main/java/org/hyperledger/besu/config/Log4j2ConfiguratorUtil.java
Outdated
Show resolved
Hide resolved
besu/src/main/java/org/hyperledger/besu/cli/subcommands/RetestethSubCommand.java
Outdated
Show resolved
Hide resolved
@garyschulte I completely missed |
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 checked about 50% of the files and managed to find one typo :)
...er/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java
Outdated
Show resolved
Hide resolved
What is your opinion on also including slf4j-lambda as another facade on top the SLF4J? They support the nice lambda syntax from log4j2. See https://stackoverflow.com/a/48725206/550859 Personally, I would like us to wait with this change until SLF4J 2.0.0 gets out of alpha. The 1.x version has to support Java 6 and as such cannot support lambdas. The 2.0.0 is in alpha already for years, however, and they have more PRs open than closed, it seems. I feel like the new ways of writing code, like for instance the lambda syntax when logging, reduces the cognitive load on people, so I would be unhappy to lose it. |
@gezero I think it would be easier to move to slf4j 2.x, when it's ready, starting from this PR than without it. In this PR there were 17 lambdas replaced with the |
@diega I agree that the migration to SLF4J 2.0 might be easier from 1.x than from log4j2. What I find a concern is that SLF4J 2.0 release is nowhere near in sight. Therefore, we might be stuck on 1.x for an undefined amount of time. I suggest for consideration that the supplier pattern is superior to the previous pattern to the extent that it might not be worth migrating to 1.x at all. I am guessing the pattern is not used much, mostly because people are not aware of it. In any case, I want to avoid blocking this effort. I can only imagine how much work it took to do all these changes. That is why I suggested to also include the slf4j-lambda. |
cb341fe
to
60d4bce
Compare
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 am 👍 for this PR, just waiting for consensus about if/what we should do for FATAL.
Will using FATAL simply map to ERROR if we do nothing?
@garyschulte |
b0c783f
to
7febfec
Compare
I'm generally 👍 for this, but before we commit given the size and scope I would want sonar to read zero bugs, vulnerabilities, security, and code smells, all ideally fix with code and without any overrides. If some of the rules are bogus for how we work we should disable them in the scan itself rather than using code annotations. |
@shemnon sure, that makes perfect sense. I'll fix them and I'll come up with a discussion if there is some that couldn't be fixed |
2f677bb
to
f35aad0
Compare
I addressed most of the Sonar issues in 22e2256 and 4ad2493. |
Reviewed and waived the outstanding issues
If the merge doesn't add any other sonar issues I am +1 to merge. |
Signed-off-by: Diego López León <dieguitoll@gmail.com>
Signed-off-by: Diego López León <dieguitoll@gmail.com>
This is for keeping compatibility with SLF4J. If neccesary, a specific formatter can be created for the RlpBlockImporter class Signed-off-by: Diego López León <dieguitoll@gmail.com>
This is because it's not possible to resolve the root logger level into a Log4J2 field Signed-off-by: Diego López León <dieguitoll@gmail.com>
org.hyperledger.besu.cli.BesuCommand#setAllLevels was taken from https://github.com/apache/logging-log4j2/blob/rel%2F2.17.1/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java#L309 Signed-off-by: Diego López León <dieguitoll@gmail.com>
Signed-off-by: Diego López León <dieguitoll@gmail.com>
Exceptions should be either logged or rethrown but not both Signed-off-by: Diego López León <dieguitoll@gmail.com>
Printf-style format strings should be used correctly Signed-off-by: Diego López León <dieguitoll@gmail.com>
Signed-off-by: Diego López León <dieguitoll@gmail.com>
Kudos, SonarCloud Quality Gate passed! |
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.
Thank you @diega for all your hard work on this. 🚢
@@ -25,6 +25,7 @@ | |||
- Re-order external services (e.g JsonRpcHttpService) to start before blocks start processing [#3118](https://github.com/hyperledger/besu/pull/3118) | |||
- Stream JSON RPC responses to avoid creating big JSON strings in memory [#3076](https://github.com/hyperledger/besu/pull/3076) | |||
- Ethereum Classic Mystique Hard Fork [#3256](https://github.com/hyperledger/besu/pull/3256) | |||
- Move into SLF4J as logging facade [#3285](https://github.com/hyperledger/besu/pull/3285) |
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.
nit: this change will be in RC3 not RC2
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 only thing is the changelog entry should be in RC3 not RC2
* Bump SLF4J version Signed-off-by: Diego López León <dieguitoll@gmail.com> * Replace log4j2 API with SLF4j API Signed-off-by: Diego López León <dieguitoll@gmail.com> * Replace usage of LogManager#getFormatterLogger This is for keeping compatibility with SLF4J. If neccesary, a specific formatter can be created for the RlpBlockImporter class Signed-off-by: Diego López León <dieguitoll@gmail.com> * Unset the default logging value for the retesteth This is because it's not possible to resolve the root logger level into a Log4J2 field Signed-off-by: Diego López León <dieguitoll@gmail.com> * Prevent creation of Logger context outside SLF4J org.hyperledger.besu.cli.BesuCommand#setAllLevels was taken from https://github.com/apache/logging-log4j2/blob/rel%2F2.17.1/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java#L309 Signed-off-by: Diego López León <dieguitoll@gmail.com> * Add FATAL level deprecation message Signed-off-by: Diego López León <dieguitoll@gmail.com> * [Sonar] Fix java:S2139 Exceptions should be either logged or rethrown but not both Signed-off-by: Diego López León <dieguitoll@gmail.com> * [Sonar] Fix java:S3457 Printf-style format strings should be used correctly Signed-off-by: Diego López León <dieguitoll@gmail.com> * Add changelog Signed-off-by: Diego López León <dieguitoll@gmail.com>
PR description
Given the latest events regarding Log4J2 security issues and the advent of Besu modularization, it would be interesting to introduce an abstraction layer for logging so we don't force any implementation for future adopters.
This PR replaces every
org.apache.logging.log4j.Logger
instance with its analogorg.slf4j.Logger
but still respects every hard dependency on Log4J2 (now more easily identifiable). Also, a new helper was introduced to deal with situations where aorg.apache.logging.log4j.core.LoggerContext
was created outside the scope of SLF4J.This is quite large to review so I kept different commits for the different decisions being made
Logger
instances, but there are also some other minor changes for respecting the same behavior of Log4J2 in SLF4j, e.g. wrap in anif (LOG.isXxxxEnabled)
values that would have been resolved through lambdas in Log4J2.retesteth
subcommandFATAL
value option and maps it toERROR
Changelog