Skip to content
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 core.Logger#setLevel method should work like Configurator#setLevel #2281

Closed
ppkarwasz opened this issue Feb 12, 2024 · 4 comments
Closed
Assignees
Labels
api Affects the public API bug Incorrect, unexpected, or unintended behavior of existing code
Milestone

Comments

@ppkarwasz
Copy link
Contributor

The main difference between the core.Logger#setLevel method and Configurator#setLevel is that the former changes only the level of a specific logger, while the latter also changes the level of child loggers.

As documented in its Javadoc, the core.Logger#setLevel method is not part of the public API (so it can do whatever it wants). However it is used in log4j-1.2-api and log4j-jul instead of the more correct Configurator#setLevel method and it causes those modules to misbehave.

We can therefore:

  • either change the way Logger#setLevel works to match the behavior of Configurator#setLevel (IMHO it is the best option, since it prevents mistakes from committers and users),
  • or simply replace Logger#setLevel with Configurator#setLevel in log4j-1.2-api and log4j-jul.
@ppkarwasz ppkarwasz added the bug Incorrect, unexpected, or unintended behavior of existing code label Feb 12, 2024
@ppkarwasz ppkarwasz added this to the 2.23.0 milestone Feb 12, 2024
@garydgregory
Copy link
Member

garydgregory commented Feb 12, 2024

I was bitten by this issue in Apache Commons Logging.

@vy
Copy link
Member

vy commented Feb 12, 2024

The main difference between the core.Logger#setLevel method and [Configurator#setLevel](https://logging.apache.org/log4j/2.x/javadoc/log4j-
We can therefore:

  1. either change the way Logger#setLevel works to match the behavior of Configurator#setLevel (IMHO it is the best option, since it prevents mistakes from committers and users),
  2. or simply replace Logger#setLevel with Configurator#setLevel in log4j-1.2-api and log4j-jul.

Thanks for investigation, @ppkarwasz. I would like to add a 3rd option to the list above:

  1. do both (would be of my preference)

@vy vy added the api Affects the public API label Feb 12, 2024
garydgregory added a commit to garydgregory/logging-log4j2 that referenced this issue Feb 13, 2024
garydgregory added a commit to garydgregory/logging-log4j2 that referenced this issue Feb 13, 2024
garydgregory added a commit that referenced this issue Feb 14, 2024
* The core.Logger#setLevel method should work like
Configurator#setLevel #2281

* Fix `Logger#setLevel` to work as in Log4j 1.2

---------

Co-authored-by: Piotr P. Karwasz <piotr.github@karwasz.org>
@garydgregory
Copy link
Member

TY @ppkarwasz for helping out with #2282, merged! 👍

@ppkarwasz
Copy link
Contributor Author

Let's leave this issue open, until we check log4j-jul.

garydgregory added a commit to garydgregory/logging-log4j2 that referenced this issue Feb 15, 2024
Configurator#setLevel apache#2281

Do for this module what we did for log4j-1.2-api
garydgregory added a commit to garydgregory/logging-log4j2 that referenced this issue Feb 15, 2024
Configurator#setLevel apache#2281

Do for this module what we did for log4j-1.2-api
garydgregory added a commit to garydgregory/logging-log4j2 that referenced this issue Feb 15, 2024
Configurator#setLevel apache#2281

Do for this module what we did for log4j-1.2-api
garydgregory added a commit that referenced this issue Feb 15, 2024
…ator#setLevel() (#2289)

* [Issue2281]  The core.Logger#setLevel method should work like
Configurator#setLevel #2281

Do for this module what we did for log4j-1.2-api

* Update log4j-jul/src/test/java/org/apache/logging/log4j/jul/test/CoreLoggerTest.java

Co-authored-by: Piotr P. Karwasz <piotr@github.copernik.eu>

---------

Co-authored-by: Piotr P. Karwasz <piotr@github.copernik.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Affects the public API bug Incorrect, unexpected, or unintended behavior of existing code
Projects
None yet
Development

No branches or pull requests

3 participants