1 24 25 package org.objectweb.cjdbc.console.gui.threads; 26 27 import java.net.Socket ; 28 29 import javax.swing.JTextArea ; 30 31 import org.apache.log4j.BasicConfigurator; 32 import org.apache.log4j.Layout; 33 import org.apache.log4j.LogManager; 34 import org.apache.log4j.PatternLayout; 35 import org.apache.log4j.WriterAppender; 36 import org.apache.log4j.net.SocketNode; 37 import org.objectweb.cjdbc.console.gui.jtools.JTextAreaWriter; 38 39 45 public class GuiLoggingThread extends Thread 46 { 47 private Socket logSocket; 48 private SocketNode node; 49 private JTextArea loggingTextPane; 50 private String host; 51 private Thread nodeThread; 52 53 59 public GuiLoggingThread(JTextArea loggingTextPane, String host) 60 { 61 super(); 62 this.host = host; 63 this.loggingTextPane = loggingTextPane; 64 } 65 66 71 public String getHost() 72 { 73 return host; 74 } 75 78 public void run() 79 { 80 try 81 { 82 BasicConfigurator.configure(); 83 JTextAreaWriter writer = new JTextAreaWriter(loggingTextPane); 84 Layout layout = new PatternLayout("%d %-5p %c{3} %m\n"); 85 WriterAppender appender = new WriterAppender(layout, writer); 86 appender.setImmediateFlush(true); 87 LogManager.getRootLogger().removeAllAppenders(); 88 LogManager.getRootLogger().addAppender(appender); 89 logSocket = new Socket (host, 9010); 90 node = new SocketNode(logSocket, LogManager.getLoggerRepository()); 91 nodeThread = new Thread (node); 92 nodeThread.start(); 93 } 94 catch (Exception e) 95 { 96 } 98 } 99 100 105 public void quit() 106 { 107 if(nodeThread!=null) 108 nodeThread.interrupt(); 109 } 110 } | Popular Tags |