Skip to content

Avoid levels like INFO#org.apache.log4j.Level #3085

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

Merged

Conversation

jonasrutishauser
Copy link
Contributor

If somebody (for example an external library) uses the deprecated Priority class there will be a custom level created even though there already exists a corresponding level.

Copy link

github-actions bot commented Oct 14, 2024

Job Requested goals Build Tool Version Build Outcome Build Scan®
build-macos-latest clean install 3.9.8 Build Scan PUBLISHED
build-ubuntu-latest clean install 3.9.8 Build Scan PUBLISHED
build-windows-latest clean install 3.9.8 Build Scan PUBLISHED
Generated by gradle/develocity-actions

@ppkarwasz
Copy link
Contributor

ppkarwasz commented Oct 15, 2024

@jonasrutishauser,

Nice catch!

Looking at the o.a.l.Priority class there are other things that can go wrong:

  1. Priority.version2Level can be null. This might lead to incorrect filtering of Priority instances (possibly even an NPE). Can you create a new package-private constructor that always sets this field to a non-null value:
    this.version2Level = version2Equivalent != null ? version2Equivalent : OptionConverter.createLevel(this);
  2. The Priority.FATAL, Priority.ERROR and so on fields reference the Level subclass, which might lead to class loading deadlocks on some JVMs (or they might just be null on others). Can you create them using the new constructor instead?
  3. Can you add test cases to LevelTest and PriorityTest to check if all the constants have the expected Log4j 2 level?

@ppkarwasz ppkarwasz self-assigned this Oct 23, 2024
This fixes the conversions of Log4j 1 `o.a.l.Priority` from and to a
Log4j2 `o.a.l.l.Level`.
@ppkarwasz ppkarwasz force-pushed the avoid-custom-level-if-not-needd branch from 0fb1635 to 89f80f1 Compare October 24, 2024 07:06
@ppkarwasz ppkarwasz merged commit 89f80f1 into apache:2.x Oct 24, 2024
5 of 6 checks passed
@ppkarwasz
Copy link
Contributor

@jonasrutishauser,

Thank You for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants