ppkarwasz commented on issue #3336:
URL: 
https://github.com/apache/logging-log4j2/issues/3336#issuecomment-2588194067

   The fix must be done in code.
   
   The basic problem is that the resolution of script references is done in 
constructors or factory methods of script-enabled components. For example in 
[`ScriptFilter`](https://logging.apache.org/log4j/2.x/manual/filters.html#Script)
 we have this snippet in the `createFilter` method:
   
   
https://github.com/apache/logging-log4j2/blob/5496c7250184e6460651eb966e8913dd0f3fe341/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/ScriptFilter.java#L148-L157
   
   Since the constructors of Log4j components are called in the order the 
components are declared in the configuration file, something like this will 
fail:
   
   ```xml
   <ScriptFilter>
     <ScriptRef ref="GLOBAL_FILTER"/>
   </ScriptFilter>
   <Scripts>
     <ScriptFile name="GLOBAL_FILTER"
                 language="groovy"
                 path="global-filter.groovy"/>
   </Scripts>
   ```
   
   will fail, since at the moment `ScriptRef` is resolved, the `ScriptFile` 
element has not been processed yet. To solve this problem, the resolution of 
`ScriptRef`s must be delayed. For example you can perform the resolution in the 
`start()` method of the 
[`LifeCycle`](https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/LifeCycle.html)
 interface.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to