ppkarwasz commented on code in PR #3394:
URL: https://github.com/apache/logging-log4j2/pull/3394#discussion_r1917905312


##########
log4j-core-test/src/test/resources/log4j-script-filters.xml:
##########
@@ -18,7 +18,13 @@
 <Configuration status="ERROR">
   <Appenders>
     <List name="List">
-      <PatternLayout pattern="[%-5level] %c{1.} %msg%n"/>
+      <PatternLayout pattern="[%-5level] %c{1.} %msg%n"/>[suvrat@suvrat 
logging-log4j2]$ git push
+Username for 'https://github.com': suvrat1629
+Password for 'https://suvrat1...@github.com':
+remote: Support for password authentication was removed on August 13, 2021.
+remote: Please see 
https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls
 for information on currently recommended modes of authentication.
+fatal: Authentication failed for 
'https://github.com/Suvrat1629/logging-log4j2.git/'
+

Review Comment:
   How did this end up here? :wink:
   
   [In the mean time I am checking if I didn't leave any `:x` or `:wq` in the 
code :stuck_out_tongue: ]



##########
log4j-core/src/main/java/org/apache/logging/log4j/core/filter/ScriptFilter.java:
##########
@@ -57,58 +57,67 @@ private ScriptFilter(
         this.configuration = configuration;
     }
 
+    @Override
+    public void start() {
+        super.start();
+        if (script instanceof ScriptRef) {
+            AbstractScript resolvedScript = 
configuration.getScriptManager().getScript(script.getName());
+            if (resolvedScript == null) {
+                LOGGER.error("No script with name {} has been declared.", 
script.getName());
+                // Optionally: mark the filter as unusable or handle failure 
gracefully
+                return;
+            }
+            this.script = resolvedScript; // Update to resolved script
+        } else {
+            if (!configuration.getScriptManager().addScript(script)) {
+                LOGGER.error("Failed to add script {} to the ScriptManager.", 
script.getName());
+            }
+        }
+    }

Review Comment:
   You can not use the same code as in the `createFilter` factory method: if 
the `script` variable is `null` it will create problems further down in the 
call hierarchy.



-- 
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