I have a Java logger that currently outputs to a file using the settings specified below. I also have a JavaFX TextArea and I want my logger to write to both the file and the TextArea concurrently.
Logger settings:
java.util.logging.FileHandler.level = ALL
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.append = true
java.util.logging.FileHandler.pattern = log.txt
Logger declaration:
static Logger LOGGER;
static {
try(FileInputStream ins = new FileInputStream("src/main/resources/log.config")) {
LogManager.getLogManager().readConfiguration(ins);
LOGGER = Logger.getLogger(BuildGet.class.getName());
initialContext = new InitialContext();
} catch (NamingException | IOException e) {
LOGGER.log(Level.WARNING,"ERROR LOGGER", e);
}
}
JavaFX TextArea:
```xml``<TextArea layoutX="20.0" layoutY="755.0" prefHeight="80.0" prefWidth="560.0" fx:id="logTextArea"/>`
An error occurs while playing the example:
javafx.fxml.LoadException:
/C:/Users/slizo/Desktop/DConsole/target/classes/DConsoleScene.fxml:18
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:944)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:981)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:230)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:755)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2808)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2634)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2516)
at jmxClientConsole.gui.DConsoleFrame.start(DConsoleFrame.java:46)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NoSuchMethodException: jmxClientConsole.DConsoleFrameControllerGetMessage.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3349)
at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2553)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:939)
... 17 more
Here is my startup class:
package jmxClientConsole.gui;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import jmxClientConsole.BuildGet;
import jmxClientConsole.TextAreaHandler;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
public class ConsoleFrame extends Application {
static Logger LOGGER;
static {
try(FileInputStream ins = new FileInputStream("src/main/resources/log.config")) {
LogManager.getLogManager().readConfiguration(ins);
LOGGER = Logger.getLogger(BuildGet.class.getName());
LOGGER.setUseParentHandlers(false);
} catch (IOException e) {
LOGGER.log(Level.WARNING," Eror ConsoleFrame ", e);
}
}
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
try {
FXMLLoader loader = new FXMLLoader();
URL xmlUrl = getClass().getResource("/ConsoleScene.fxml");
loader.setLocation(xmlUrl);
TextArea textArea = new TextArea();
textArea.setEditable(false);
textArea.setFont(Font.font("Monospaced", 13));
TextAreaHandler handler = new TextAreaHandler(textArea);
handler.setFormatter(new SimpleFormatter());
LOGGER.addHandler(handler);
Parent root = loader.load();
stage.setTitle("Console");
stage.getIcons().add(new Image(ConsoleFrame.class.getClassLoader().getResourceAsStream("logoC.png")));
stage.setScene(new Scene(root));
stage.show();
LOGGER.log(Level.INFO,"Success console ");
} catch (Exception e) {
LOGGER.log(Level.SEVERE,"Eror Console", e);
}
}
}
What I wrote in the comment about the controller, I had this. I have all the logic of the buttons in it:
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="900.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="jmxClientConsole.ConsoleFrameControllerGetMessage">