Java – how to get logger value in string array
•
Java
I use log4j Logger, and I have used fileappender to write log values to files
Now I want to display the log values in textarea How do I assign logger values to string arrays?
Solution
You can add an additional appender to the logger Use writerappender to write a stringwriter, and then change the content of 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 an intelligent way to update your textarea, depending on the loglevel, if the contents of the stringwriter change
Update: provide comparable solutions here
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码