I’m working on porting my plugin JPanel to sponge, but I’m struggling to port one of the features to Sponge. Specifically, how to send the output of the console via a websocket to the panel.
In bukkit, I used private static final org.apache.logging.log4j.core.Logger logger = (org.apache.logging.log4j.core.Logger) LogManager.getRootLogger(); to get the main server logger, then in the websocket class I attached the following Appender to the log in order to capture each line of the console and send it to the web socket:
private class LogHandler extends AbstractAppender {
private ConsoleSocket socket;
public LogHandler(ConsoleSocket socket) {
super("ConsoleSocket", null, null);
this.socket = socket;
start();
}
@Override
public void append(LogEvent event) {
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
Date date = new Date();
String message = event.getMessage().getFormattedMessage();
appendMessage(dateFormat.format(date) + " [" + event.getLevel() + "] " + message);
}
}
However, in Sponge this code doesn’t seem to work properly. It only appears to get logs from the plugin, and not the rest of the server. What would be the correct way of doing this?
Yeah, I’m not really sure how this would be handled. I’m doing some work on improving logging, so I’ll take a look at making redirecting output easy – it’d be done through the ConsoleSource (game.getServer().getConsole()).
Awesome! I plan to add some stuff to logging that will give you a proper way to do that (intercepting output & stuff) and allow logging Text output (so formatting logging is more embedded in the system).
That’ll allow more flexible filtering and capturing of log messages.