[ 
https://issues.apache.org/jira/browse/LOG4J2-3652?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Piotr Karwasz reassigned LOG4J2-3652:
-------------------------------------

    Assignee: Matt Sicker  (was: Piotr Karwasz)

> jlink creates broken runtime image when using "--strip-debug" flag
> ------------------------------------------------------------------
>
>                 Key: LOG4J2-3652
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3652
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: API, Core, Plugins
>    Affects Versions: 3.0.0
>            Reporter: Jannik Zuther
>            Assignee: Matt Sicker
>            Priority: Minor
>
> I'm trying out the current `3.0.0-SNAPSHOT` (not sure if they have a unique 
> ID, but I got them on 2023-03-03) because I want to use Log4j 2 in a project 
> with `jlink`. I've used `api`, `core`, and (transitively) `plugins`.
> I'm using programmatic configuration (no configuration file), if that matters.
> When using `jlink` with the `--strip-debug` flag with Log4j 2, the resulting 
> runtime image seems to be broken. When trying to run it, Log4j 2 immediately 
> spits out a giant number of errors and exceptions.
> It looks like the Log4j 2 components essentially can't find their own 
> attributes, nor the attributes of other components?
> (EDIT: I don't know how to do inline code formatting here.)
> Here is some of the output (it's far too much to include it all):
> {code:java}
> ERROR StatusConsoleListener Appender references must contain a reference: arg0
> ERROR StatusConsoleListener Could not configure plugin element AppenderRef: 
> org.apache.logging.log4j.plugins.validation.ConstraintValidationException: 
> Validation failed for arg0 (source: java.lang.String arg0) and value null
>  org.apache.logging.log4j.plugins.validation.ConstraintValidationException: 
> Validation failed for arg0 (source: java.lang.String arg0) and value null
>         at 
> [email protected]/org.apache.logging.log4j.plugins.di.DefaultInjector.validate(Unknown
>  Source)
>         at 
> [email protected]/org.apache.logging.log4j.plugins.di.DefaultInjector.lambda$getArguments$37(Unknown
>  Source)
> [...]
> {code}
> {code:java}
> ERROR StatusConsoleListener AppenderRef contains an invalid element or 
> attribute "ref"
> ERROR StatusConsoleListener Appender references must contain a reference: arg0
> ERROR StatusConsoleListener Could not configure plugin element AppenderRef: 
> org.apache.logging.log4j.plugins.validation.ConstraintValidationException: 
> Validation failed for arg0 (source: java.lang.String arg0) and value null
> [...]
> {code}
> {code:java}
> [...]
> ERROR StatusConsoleListener Logger contains invalid attributes "name", "level"
> ERROR StatusConsoleListener Logger has no field or parameter that matches 
> element AppenderRef
> ERROR StatusConsoleListener Logger has no field or parameter that matches 
> element AppenderRef
> ERROR StatusConsoleListener Skipping null child object with name Logger in 
> element Loggers
> ERROR StatusConsoleListener Loggers has no field or parameter that matches 
> element Logger
> ERROR StatusConsoleListener ThresholdFilter contains an invalid element or 
> attribute "level"
> ERROR StatusConsoleListener ThresholdFilter contains an invalid element or 
> attribute "level"
> [...]
> {code}
> When not using the `--strip-debug` flag, things seem to work fine.
> Is this a known issue? Or even expected behavior? What is Log4j 2 doing that 
> could be causing this? I can barely find any information about what exactly 
> `--strip-debug` even strips from the runtime image.
> Is this a problem related to reflection, possibly?
> While the workaround is just not adding `--strip-debug`, this would likely 
> trip up more people in the future. I spent almost two days until I found out 
> that this was even the problem (which might just be my inexperience with the 
> Java Platform Module System, though).
> To reproduce this:
> - Create a Java or Kotlin-JVM application that depends on Log4j 2 
> `3.0.0-SNAPSHOT` and that has a `module-info.java`
> - Do some Log4j things in the main method, like creating a logger and logging 
> something
> - Create a runtime image from your application with `jlink`, including the 
> `--strip-debug` flag
> - Run that runtime image and observe the output



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to