[logback-user] Custom TextAreaAppender

m.lippa at ads.it m.lippa at ads.it
Tue Nov 6 10:55:23 CET 2012

Hi all,
I'm switching my first java desktop application from log4j to logback, 
mainly because we neede a reliable DailyRollingFileAppender, and we were 
told the log4j implementation is not.
So far all ok, we simply changed the Logger declaration and all worked 
The problem is our custom TextAreaAppender we are currently using to log 
the events to a text area in the application. The log4j implementation is 
very simple:

public class TextAreaAppender extends WriterAppender {

    static private JTextArea jTextArea = null;
    public static void setTextArea(JTextArea jTextArea) {
        TextAreaAppender.jTextArea = jTextArea;

     * Format and then append the loggingEvent to the stored JTextArea.
    public void append(LoggingEvent loggingEvent) {
        if (layout != null) {
            final String message = layout.format(loggingEvent);
            StringBuilder sb = new StringBuilder();
            if (loggingEvent.getThrowableInformation() != null) {
                String[] stackTrace = loggingEvent.getThrowableStrRep();
                for (String s : stackTrace) {
            final String stackTrace = sb.toString();

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    if (jTextArea != null) {
                        if (!stackTrace.isEmpty()) {

I worked a couple of day but did not manage to get a logback version of 
this appender to work. Do you have any sample code available?

thanks in advance

Questa e-mail ed i suoi allegati sono ad uso esclusivo di coloro ai quali è indirizzata e potrebbe contenere informazioni riservate, la cui diffusione, copia e/o distribuzione è proibita. Qualora riceveste questo messaggio per errore, scusandoci per l'accaduto, Vi preghiamo di avvertirci immediatamente, distruggendo quanto ricevuto. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20121106/8f04d4b7/attachment.html>

More information about the Logback-user mailing list