Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » log4j appender for SWT Text(how to set one?)
log4j appender for SWT Text [message #780213] Tue, 17 January 2012 06:28 Go to next message
et was is currently offline et was
Messages: 2
Registered: July 2010
Junior Member
hello,

this should be fairly easy and probably already known. how to set log4j appender for Text?

currently struggling with SWT "invalid thread access" issue...

thank you.
et.
Re: log4j appender for SWT Text [message #780218 is a reply to message #780213] Tue, 17 January 2012 06:48 Go to previous message
et was is currently offline et was
Messages: 2
Registered: July 2010
Junior Member
crap, as usually after posting i figured out an answer.. sorry for unnecessary turmoil.

i post below the solution, if any1 needs it.

--------------------------------------------------------------------
import org.apache.log4j.WriterAppender;
import org.apache.log4j.spi.LoggingEvent;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;

public class SwtTextAppenderLog4J extends WriterAppender
{

    private static Text text;
    private static Display display;
        
    static public void set(Display display, Text text)
    {
        SwtTextAppenderLog4J.display = display;
        SwtTextAppenderLog4J.text = text;
    }

    public void append(LoggingEvent loggingEvent)
    {
        if(text == null || display == null)
        {
            return;
        }
        
        final String mes = (String) loggingEvent.getMessage();

        display.asyncExec(new Runnable()
        {
            
            @Override
            public void run()
            {
                if(text != null)
                {
                    text.append(mes + "\n");
                } 
            }
        });
    }

}

Previous Topic:Drag & Drop table - dragging items down past window too slow
Next Topic:Expandbar in an Expandbar
Goto Forum:
  


Current Time: Thu Apr 17 11:29:22 EDT 2014

Powered by FUDForum. Page generated in 0.03706 seconds