diff --git a/Ghidra/Debug/Framework-Debugging/certification.manifest b/Ghidra/Debug/Framework-Debugging/certification.manifest
index 84620e1e60..5bbc754b9b 100644
--- a/Ghidra/Debug/Framework-Debugging/certification.manifest
+++ b/Ghidra/Debug/Framework-Debugging/certification.manifest
@@ -1,4 +1,7 @@
##VERSION: 2.0
Module.manifest||GHIDRA||||END|
data/ExtensionPoint.manifest||GHIDRA||||END|
+src/main/resources/agent.log4j.xml||GHIDRA||||END|
+src/main/resources/log4j-appender-console.xml||GHIDRA||||END|
+src/main/resources/log4j-appender-logpanel.xml||GHIDRA||||END|
src/test/resources/ghidra/dbg/model/test_schema.xml||GHIDRA||||END|
diff --git a/Ghidra/Debug/Framework-Debugging/src/main/java/ghidra/dbg/agent/AgentWindow.java b/Ghidra/Debug/Framework-Debugging/src/main/java/ghidra/dbg/agent/AgentWindow.java
index 0681d442ad..6cf4961152 100644
--- a/Ghidra/Debug/Framework-Debugging/src/main/java/ghidra/dbg/agent/AgentWindow.java
+++ b/Ghidra/Debug/Framework-Debugging/src/main/java/ghidra/dbg/agent/AgentWindow.java
@@ -23,27 +23,18 @@ import java.net.SocketAddress;
import javax.swing.*;
import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.appender.AbstractAppender;
-import org.apache.logging.log4j.core.config.Property;
+import org.apache.logging.log4j.core.config.Configuration;
-public class AgentWindow extends JFrame implements WindowListener {
- public static final int MAX_LOG_CHARS = 10000;
+import ghidra.framework.LoggingInitialization;
+import ghidra.util.Msg;
+import ghidra.util.Swing;
+import log.LogListener;
+import log.LogPanelAppender;
- protected class WindowAppender extends AbstractAppender {
- protected WindowAppender() {
- super("agentAppender", null, null, true, Property.EMPTY_ARRAY);
- }
-
- @Override
- public void append(LogEvent event) {
- String allText = logArea.getText() + "\n" + event.getMessage().getFormattedMessage();
- logArea.setText(
- allText.substring(Math.max(0, allText.length() - MAX_LOG_CHARS), allText.length()));
- // TODO: Scroll to bottom
- }
- }
+public class AgentWindow extends JFrame implements WindowListener, LogListener {
+ public static final int MAX_LOG_CHARS = 100000;
protected final JTextArea logArea = new JTextArea();
protected final JScrollPane logScroll = new JScrollPane(logArea);
@@ -55,15 +46,38 @@ public class AgentWindow extends JFrame implements WindowListener {
add(new JLabel("This agent is listening at " + localAddress +
". Close this window to terminate it."), BorderLayout.NORTH);
logArea.setEditable(false);
- logArea.setFont(Font.getFont(Font.MONOSPACED));
+ logArea.setFont(Font.decode(Font.MONOSPACED));
logArea.setAutoscrolls(true);
logScroll.setAutoscrolls(true);
add(logScroll);
setMinimumSize(new Dimension(400, 300));
setVisible(true);
+ System.setProperty("log4j.configuration", "agent.log4j.xml");
+ LoggingInitialization.initializeLoggingSystem();
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
- ctx.getConfiguration().addAppender(new WindowAppender());
+ Configuration config = ctx.getConfiguration();
+ Appender appender = config.getAppender("logPanel");
+ if (!(appender instanceof LogPanelAppender)) {
+ Msg.error(this, "Couldn't find LogPanelAppender instance in the Log4j context. " +
+ "Nothing will be logged to the agent's window.");
+ }
+ else {
+ LogPanelAppender logPanelAppender = (LogPanelAppender) appender;
+ logPanelAppender.setLogListener(this);
+ }
+ }
+
+ @Override
+ public void messageLogged(String message, boolean isError) {
+ String fMessage = isError ? "" + message + "" : message;
+ Swing.runIfSwingOrRunLater(() -> {
+ String allText = logArea.getText() + fMessage + "\n";
+ logArea.setText(
+ allText.substring(Math.max(0, allText.length() - MAX_LOG_CHARS), allText.length()));
+ JScrollBar vScroll = logScroll.getVerticalScrollBar();
+ vScroll.setValue(vScroll.getMaximum());
+ });
}
@Override
diff --git a/Ghidra/Debug/Framework-Debugging/src/main/resources/agent.log4j.xml b/Ghidra/Debug/Framework-Debugging/src/main/resources/agent.log4j.xml
new file mode 100644
index 0000000000..3f75fa4f4d
--- /dev/null
+++ b/Ghidra/Debug/Framework-Debugging/src/main/resources/agent.log4j.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Ghidra/Debug/Framework-Debugging/src/main/resources/log4j-appender-console.xml b/Ghidra/Debug/Framework-Debugging/src/main/resources/log4j-appender-console.xml
new file mode 100644
index 0000000000..f1e2365c18
--- /dev/null
+++ b/Ghidra/Debug/Framework-Debugging/src/main/resources/log4j-appender-console.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
diff --git a/Ghidra/Debug/Framework-Debugging/src/main/resources/log4j-appender-logpanel.xml b/Ghidra/Debug/Framework-Debugging/src/main/resources/log4j-appender-logpanel.xml
new file mode 100644
index 0000000000..ce2a41dcee
--- /dev/null
+++ b/Ghidra/Debug/Framework-Debugging/src/main/resources/log4j-appender-logpanel.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+