-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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://[email protected]': | ||
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/' | ||
|
||
</List> | ||
</Appenders> | ||
<Loggers> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,9 +42,9 @@ | |
@Plugin(name = "ScriptFilter", category = Node.CATEGORY, elementType = Filter.ELEMENT_TYPE, printObject = true) | ||
public final class ScriptFilter extends AbstractFilter { | ||
|
||
private static org.apache.logging.log4j.Logger logger = StatusLogger.getLogger(); | ||
private static final org.apache.logging.log4j.Logger LOGGER = StatusLogger.getLogger(); | ||
|
||
private final AbstractScript script; | ||
private AbstractScript script; | ||
private final Configuration configuration; | ||
|
||
private ScriptFilter( | ||
|
@@ -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()); | ||
} | ||
} | ||
} | ||
Comment on lines
+61
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can not use the same code as in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so should i just revert back the changes i made to the ScriptFilter.java file and and make changes to the processRootNode method in the AbstractConfiguration and update the logic? is this how i should keep my approach? Also thanks for your patience and guidance :) |
||
|
||
@Override | ||
public Result filter( | ||
final Logger logger, final Level level, final Marker marker, final String msg, final Object... params) { | ||
final SimpleBindings bindings = new SimpleBindings(); | ||
bindings.put("logger", logger); | ||
bindings.put("level", level); | ||
bindings.put("marker", marker); | ||
bindings.put("message", new SimpleMessage(msg)); | ||
bindings.put("parameters", params); | ||
bindings.put("throwable", null); | ||
bindings.putAll(configuration.getProperties()); | ||
bindings.put("substitutor", configuration.getStrSubstitutor()); | ||
final Object object = configuration.getScriptManager().execute(script.getName(), bindings); | ||
return object == null || !Boolean.TRUE.equals(object) ? onMismatch : onMatch; | ||
return executeScript(logger, level, marker, new SimpleMessage(msg), params, null); | ||
} | ||
|
||
@Override | ||
public Result filter( | ||
final Logger logger, final Level level, final Marker marker, final Object msg, final Throwable t) { | ||
final SimpleBindings bindings = new SimpleBindings(); | ||
bindings.put("logger", logger); | ||
bindings.put("level", level); | ||
bindings.put("marker", marker); | ||
bindings.put("message", msg instanceof String ? new SimpleMessage((String) msg) : new ObjectMessage(msg)); | ||
bindings.put("parameters", null); | ||
bindings.put("throwable", t); | ||
bindings.putAll(configuration.getProperties()); | ||
bindings.put("substitutor", configuration.getStrSubstitutor()); | ||
final Object object = configuration.getScriptManager().execute(script.getName(), bindings); | ||
return object == null || !Boolean.TRUE.equals(object) ? onMismatch : onMatch; | ||
Message message = msg instanceof String ? new SimpleMessage((String) msg) : new ObjectMessage(msg); | ||
return executeScript(logger, level, marker, message, null, t); | ||
} | ||
|
||
@Override | ||
public Result filter( | ||
final Logger logger, final Level level, final Marker marker, final Message msg, final Throwable t) { | ||
return executeScript(logger, level, marker, msg, null, t); | ||
} | ||
|
||
@Override | ||
public Result filter(final LogEvent event) { | ||
final SimpleBindings bindings = new SimpleBindings(); | ||
bindings.put("logger", logger); | ||
bindings.put("level", level); | ||
bindings.put("marker", marker); | ||
bindings.put("message", msg); | ||
bindings.put("parameters", null); | ||
bindings.put("throwable", t); | ||
bindings.put("logEvent", event); | ||
bindings.putAll(configuration.getProperties()); | ||
bindings.put("substitutor", configuration.getStrSubstitutor()); | ||
final Object object = configuration.getScriptManager().execute(script.getName(), bindings); | ||
return object == null || !Boolean.TRUE.equals(object) ? onMismatch : onMatch; | ||
} | ||
|
||
@Override | ||
public Result filter(final LogEvent event) { | ||
private Result executeScript( | ||
final Logger logger, | ||
final Level level, | ||
final Marker marker, | ||
final Message msg, | ||
final Object[] params, | ||
final Throwable t) { | ||
final SimpleBindings bindings = new SimpleBindings(); | ||
bindings.put("logEvent", event); | ||
bindings.put("logger", logger); | ||
bindings.put("level", level); | ||
bindings.put("marker", marker); | ||
bindings.put("message", msg); | ||
bindings.put("parameters", params); | ||
bindings.put("throwable", t); | ||
bindings.putAll(configuration.getProperties()); | ||
bindings.put("substitutor", configuration.getStrSubstitutor()); | ||
final Object object = configuration.getScriptManager().execute(script.getName(), bindings); | ||
|
@@ -145,16 +154,6 @@ public static ScriptFilter createFilter( | |
LOGGER.error("Script support is not enabled"); | ||
return null; | ||
} | ||
if (script instanceof ScriptRef) { | ||
if (configuration.getScriptManager().getScript(script.getName()) == null) { | ||
logger.error("No script with name {} has been declared.", script.getName()); | ||
return null; | ||
} | ||
} else { | ||
if (!configuration.getScriptManager().addScript(script)) { | ||
return null; | ||
} | ||
} | ||
|
||
return new ScriptFilter(script, configuration, match, mismatch); | ||
} | ||
|
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.
How did this end up here? 😉
[In the mean time I am checking if I didn't leave any
:x
or:wq
in 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.
Well i just shifted to arch and was trying to push to code from intellij and this log ended up here after i pushed the code and i realised it just after :D