From 527b392c95405d684ae8f326352b44d7bda0cc14 Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Wed, 4 Mar 2026 07:11:49 -0500 Subject: [PATCH] GP-6532: Fixed issue with script log redirect caused by the last log4j upgrade --- .../java/ghidra/app/script/ScriptMessage.java | 15 ++++++++++++--- .../log4j-appender-rolling-file-scripts.xml | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/script/ScriptMessage.java b/Ghidra/Features/Base/src/main/java/ghidra/app/script/ScriptMessage.java index f2539b6b3d..d54be81da1 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/script/ScriptMessage.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/script/ScriptMessage.java @@ -16,6 +16,7 @@ package ghidra.app.script; import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.message.StringFormattedMessage; /** * A simple {@link Message} implementation that allows us to use the filtering capability @@ -23,14 +24,22 @@ import org.apache.logging.log4j.message.Message; * message out. Our formatted message is the original message given to us. We use the * unformatted message, in conjunction with a regex filter to allow for filtering such that * the script log file only has script messages. - * - *

See log4j-appender-rolling-file-scripts.xml + *

+ * See log4j-appender-rolling-file-scripts.xml + *

+ * NOTE: {@link Message#getFormat()} was deprecated in log4j 2.24.0, and the behavior of + * {@code useRawMsg} changed to only work with certain classes that implement the {@link Message} + * interface, such as {@link StringFormattedMessage}. Implementing our own {@link Message} + * resulted in {@code useRawMsg} not calling {@link #getFormat()}. See + * logging-log4j2/pull/2773 for + * more info. */ -public class ScriptMessage implements Message { +public class ScriptMessage extends StringFormattedMessage { private String message; public ScriptMessage(String message) { + super(message); this.message = message; } diff --git a/Ghidra/Framework/Generic/src/main/resources/log4j-appender-rolling-file-scripts.xml b/Ghidra/Framework/Generic/src/main/resources/log4j-appender-rolling-file-scripts.xml index e052b6ce35..0660de440a 100644 --- a/Ghidra/Framework/Generic/src/main/resources/log4j-appender-rolling-file-scripts.xml +++ b/Ghidra/Framework/Generic/src/main/resources/log4j-appender-rolling-file-scripts.xml @@ -5,8 +5,8 @@ Log4j appender that writes messages to a file. We filter the messages for this file by using the 'GhidraScript' text. This text is added - to the 'unformatted message' by using the log4j's Message class. We then emit the - original message when writing to the file. + to the 'unformatted message' by using our ScriptMessage class, which extends log4j's + StringFormattedMessage class. We then emit the original message when writing to the file. -->