logging-log4j2 icon indicating copy to clipboard operation
logging-log4j2 copied to clipboard

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

Open jonasrutishauser opened this issue 1 year ago • 2 comments

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.

jonasrutishauser avatar Oct 14 '24 20:10 jonasrutishauser

Job Requested goals Build Tool Version Build Outcome Build Scan®
build-macos-latest clean install 3.9.8 :white_check_mark: Build Scan PUBLISHED
build-ubuntu-latest clean install 3.9.8 :white_check_mark: Build Scan PUBLISHED
build-windows-latest clean install 3.9.8 :x: Build Scan PUBLISHED

Generated by gradle/develocity-actions

github-actions[bot] avatar Oct 14 '24 21:10 github-actions[bot]

@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 avatar Oct 15 '24 08:10 ppkarwasz

@jonasrutishauser,

Thank You for your contribution!

ppkarwasz avatar Oct 24 '24 07:10 ppkarwasz