I used the log4j.Logger
and I have written the log value in to a file using the FileAppender
.
Now I want to show the log value in a textarea. How can I assign the logger value to an array of Strings?
Read a line of the csv file and call String. split(",") on the line which will return you an array of each seperate string in the line you just read then you can simply loop through the array and print them out as you need.
log(Level level, String msg, Object[] params): This method is used to Log a message, with an array of object arguments. Output: log(Level level, String msg, Throwable thrown): This method is used to Log a message, with associated Throwable information.
The info() method of a Logger class is used to Log an INFO message. This method is used to forward logs to all the registered output Handler objects.
In case, you are using logger, then you can use log.info() to print multiple variables. Obviously, you can choose logging level based on your preference.
You can add an additional Appender
to your Logger
. Use a WriterAppender to write to a StringWriter
then you change the content of your TextArea
to the value of StringWriter#toString()
Example Code:
public static void main(String[] args) {
Logger logger = Logger.getLogger("logger");
Layout layout = new PatternLayout();
StringWriter stringWriter = new StringWriter();
WriterAppender writerAppender = new WriterAppender(layout, stringWriter);
logger.addAppender(writerAppender);
TextArea textArea = new TextArea();
logger.error("test");
//if(stringWriter changed){// compare to old TextArea-content?
textArea.setText(stringWriter.toString());
//}
//System.out.println(stringWriter.toString());
}
you need to find a smart way update your TextArea
depending on the logLevel and if the content of the StringWriter
changed.
Update: A comparable solution is presented here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With