Skip to main content


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 11:28 Go to next message
et was is currently offline et wasFriend
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 11:48 Go to previous message
et was is currently offline et wasFriend
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: Fri Apr 19 19:59:29 GMT 2024

Powered by FUDForum. Page generated in 0.03251 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top