-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Bug Fix: Script Resolution fix #3394
base: 2.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR.
Unfortunately it does not solve #3336, since we have a lot of elements that use scripting (ScriptFilter
was just an example):
ScriptPatternSelector
Routes
ScriptFilter
ScriptAppenderSelector
ScriptCondition
ScriptArbiter
RoutingAppender
To fix the resolution of scripts in all of these, I think we should take a different approach: we could alter the order in which the children of a <Configuration>
element are processed. Right now we process them in order of appearance, with a single exception: the <Properties>
element must be processed first to allow the values of the remaining elements to be properly interpolated:
Lines 668 to 688 in 6e3f2e2
for (final Node node : rootNode.getChildren()) { | |
if ("Properties".equalsIgnoreCase(node.getName())) { | |
hasProperties = true; | |
createConfiguration(node, null); | |
if (node.getObject() != null) { | |
final StrLookup lookup = node.getObject(); | |
runtimeStrSubstitutor.setVariableResolver(lookup); | |
configurationStrSubstitutor.setVariableResolver(lookup); | |
} | |
break; | |
} | |
} | |
if (!hasProperties) { | |
final Map<String, String> map = this.getComponent(CONTEXT_PROPERTIES); | |
final StrLookup lookup = map == null ? null : new PropertiesLookup(map); | |
final Interpolator interpolator = new Interpolator(lookup, pluginPackages); | |
interpolator.setConfiguration(this); | |
interpolator.setLoggerContext(loggerContext.get()); | |
runtimeStrSubstitutor.setVariableResolver(interpolator); | |
configurationStrSubstitutor.setVariableResolver(interpolator); | |
} |
We should probably process the <Scripts>
element just after <Properties>
.
Note: the ScriptArbiter
should probably be processed differently. Arbiters are special plugins that modify the structure of the configuration file before it is processed. Therefore the ScriptArbiter
should probably just signal an ERROR
(or throw), if it contains a ScriptRef
. At the stage, when the arbiter is used, the Scripts
element is not yet processed.
log4j-core/src/main/java/org/apache/logging/log4j/core/filter/ScriptFilter.java
Outdated
Show resolved
Hide resolved
The
It is hard to identify the script-related components. It is easier to make sure that the
It is one of the possible approaches, probably the easiest to implement. |
i have made the necessary fix to the code please review the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please review the files you are committing before you commit them. A lot of garbage/temporary files made their way into your PR.
Also make sure to push the minimal amount of changes, e.g. configure you IDE not to reformat comments or the lines you didn't modify.
In this project we use the Palantir Java Formatter, which is available as IntelliJ IDEA plugin, but you can also run it using:
./mvnw spotless:apply
Regarding Java imports, we don't use wildcard (*
) imports and we follow the order:
all `import static` statements
<empty line>
all `import` statements
The changes to AbstractConfiguration
look almost OK, but the unit test does not currently compile.
log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppenderBuilderTest.java
Outdated
Show resolved
Hide resolved
...-core-test/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderBuilderTest.java
Outdated
Show resolved
Hide resolved
...-core-test/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderBuilderTest.java
Outdated
Show resolved
Hide resolved
...-core-test/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderBuilderTest.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/filter/ScriptFilter.java
Outdated
Show resolved
Hide resolved
I have tried to fix the changes you have asked me and keep the pr as clean as possible however for the test cases I am not so sure because I lack knowledge about testing but if there are anymore further changes please let me know. Thank you. |
#3336
Refactored the ScriptFilter class to enhance script resolution and error handling. This update ensures that ScriptRef scripts are resolved properly using the ScriptManager. Improved logging for scenarios where scripts fail to execute or resolve.
Checklist
.Base your changes on
2.xbranch if you are targeting Log4j 2; use
main` otherwise./mvnw verify
succeeds (if it fails due to code formatting issues reported by Spotless, simply run./mvnw spotless:apply
and retry)src/changelog/.2.x.x
directory