-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
The log4j-jul
artifact should not modify logger levels
#2353
Comments
Please include your configuration file. |
Sorry, malformed opening message. There are links for the gradle output from both situations, using log4j2 2.23 and log4j 2.22.1, and the log4j2.xml configuration file. |
Running the test in a standalone environment I am not able to reproduce it. Educated guessYou are using the JUL-to-Log4j API bridge. In version My guess is that something in your code must be calling: java.util.logging.Logger.getRootLogger().setLevel(java.util.logging.Level.INFO); which in WorkaroundsIf my guess is right, setting the level to <Logger name="com.example" level="TRACE"/> Another workaround would be to set the Any chance you can set a breakpoint on |
Should we introduce in |
In my humble opinion, having external APIs messing with log4j2 configuration are bugs, not features: one of the patterns I did get from log4j2 (at least until version 2.21) is that legacy applications trying to reconfigure logs without using log4j2 api would ultimately fail. If a legacy log4j 1.x app would try a PropertyConfigurator.configure, for example, I wouldn't get all log configuration overriden by a legacy framework. |
I tend to agree with you: only the main application code should be allowed to touch the configuration of the logging backend. However there are many users that expect their legacy code to work, when they migrate from a logging backend to another, that is why these features were implemented. |
Yep, I hear you: what for some is a bug, for others is a feature :) Well, for the log4 1.x adapter, two versions were created: one that doesn't mess with configuration, and one which does change configuration and is a real drop-in replacement for applications that were using log4j 1.x. If the opener can't reconfigure logs for an API that doesn't do that since the beginning of time, it is for sure a new app, or a new log4j2 use: it would be easier to simply change the classpath to add a "log4j-jul-fullapi.jar" in their classpath instead of "log4j-jul.jar" than having everyone else that is using log4j2 for years to remove the jar or changing configurations. |
Specially if an issue arises like "everyone must change to the latest log4j2 because of CVE whatever" |
For the upcoming
|
But here is the thing: to use the release 3.x there will be massive classpath changes, if I understood well. To use log4j 3 everyone will need to change a lot of things, which makes the whole effort somewhat of a moot point. I do understand this is an issue with log4j2 2. I'm my humble opinion, this should be dealt with as a log4j patch release 2.23.1 instead of 3.x . But I can also live without upgrading to 2.23 : the changes made there really aren't "useful" to me. I will just keep a note to the team not to upgrade to it, and keep using 2.22 |
Or simply keep using only log4j2-jul 2.22. I can live with that :) |
Regarding |
@hi All, After discussing this with @ppkarwasz and looking at code, we are dealing with the following issue:
To keep the Log4j configuration pristine, I think we should:
@ppkarwasz Check? (Feel free to edit this comment). |
Thanks, that sounds the right solution. I am scheduling it for As far as I am concerned |
log4j-jul
artifact should not modify logger levels
This PR switches the default JUL `LoggerAdapter` from `CoreLoggerAdapter` to `ApiLoggerAdapter`. Level mutators in the `java.util.logging.Logger` interface will be disabled by default, unless users reenable them explicitly. Closes #2353.
Some libraries rely on `j.u.l.Logger.getLevel` returning the value that was set using `j.u.l.Logger.setLevel`. This PR changes #2353 so that: - By default, the **effective** configuration of the logging backend is not modified by `log4j-jul`. - Calling `setLevel` modifies the return value of `getLevel`. Both these methods should **not** be used in user code, because the **effective** level of a logger should be checked with `j.u.l.isLoggable` instead. Therefore, I don't see any potential problems with these modifications. Closes #3119
Description
Using log4j2 2.23 makes my logs not to show trace and debug events, not mattering what I set in the log4j2 configuration file.
Configuration
Version: 2.23.0
Operating system: Windows WSL Linux 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
JDK: Azul Zulu 21 community edition
Logs
The output using log4j 2.23
My log4j2 xml configuration
The log output with log4j 2.22.1 : notice that the expected application trace events do appear
Reproduction
[An isolated test reproducing the test.
JUnit tests similar to the ones in the code base are extremely appreciated.]
TestLog.java.txt
The output using log4j2 2.22.1 with -Dlog4j2.configurationFile=(the example file)
The output of the junit test with log4j2 2.22.1
The output of the junit test with log4j2 2.23.0
The text was updated successfully, but these errors were encountered: