FileDocCategorySizeDatePackage
TextPanelAppender.javaAPI DocApache log4j 1.2.156248Sat Aug 25 00:09:34 BST 2007org.apache.log4j.gui

TextPanelAppender

public class TextPanelAppender extends AppenderSkeleton
author
James House

Fields Summary
org.apache.log4j.helpers.TracerPrintWriter
tp
StringWriter
sw
QuietWriter
qw
LogTextPanel
logTextPanel
LogPublishingThread
logPublisher
final String
COLOR_OPTION_FATAL
final String
COLOR_OPTION_ERROR
final String
COLOR_OPTION_WARN
final String
COLOR_OPTION_INFO
final String
COLOR_OPTION_DEBUG
final String
COLOR_OPTION_BACKGROUND
final String
FONT_NAME_OPTION
final String
FONT_SIZE_OPTION
final String
EVENT_BUFFER_SIZE_OPTION
Constructors Summary
public TextPanelAppender(Layout layout, String name)


       
    this.layout = layout;
    this.name = name;
    this.sw = new StringWriter();
    this.qw = new QuietWriter(sw, errorHandler);
    this.tp = new TracerPrintWriter(qw);
    setLogTextPanel(new LogTextPanel());
    logPublisher = new LogPublishingThread(logTextPanel, Priority.ERROR, 500);
    //logPublisher = new LogPublishingThread(logTextPanel, null, 500);
  
Methods Summary
public voidappend(org.apache.log4j.spi.LoggingEvent event)


    String text = this.layout.format(event);

    // Print Stacktrace
    // Quick Hack maybe there is a better/faster way?
    if (event.throwable!=null) {
      event.throwable.printStackTrace(tp);
      for (int i=0; i< sw.getBuffer().length(); i++) {
        if (sw.getBuffer().charAt(i)=='\t")
          sw.getBuffer().replace(i,i+1,"        ");
      }
      text += sw.toString();
      sw.getBuffer().delete(0,sw.getBuffer().length());
    }
    else
      if(!text.endsWith("\n"))
        text += "\n";

    logPublisher.publishEvent(event.priority, text);
  
public voidclose()

  
public javax.swing.JPanelgetLogTextPanel()

    return logTextPanel;
  
public java.lang.String[]getOptionStrings()

    return new String[] { COLOR_OPTION_FATAL, COLOR_OPTION_ERROR,
         COLOR_OPTION_WARN, COLOR_OPTION_INFO, COLOR_OPTION_DEBUG,
         COLOR_OPTION_BACKGROUND, FONT_NAME_OPTION, FONT_SIZE_OPTION};
  
public booleanrequiresLayout()

    return true;
  
protected voidsetLogTextPanel(LogTextPanel logTextPanel)

    this.logTextPanel = logTextPanel;
    logTextPanel.setTextBackground(Color.white);
  
public voidsetName(java.lang.String name)

    this.name = name;
  
public voidsetOption(java.lang.String option, java.lang.String value)

    if (option.equalsIgnoreCase(COLOR_OPTION_FATAL))
      logTextPanel.setTextColor(Priority.FATAL,value);
    if (option.equalsIgnoreCase(COLOR_OPTION_ERROR))
      logTextPanel.setTextColor(Priority.ERROR,value);
    if (option.equalsIgnoreCase(COLOR_OPTION_WARN))
      logTextPanel.setTextColor(Priority.WARN,value);
    if (option.equalsIgnoreCase(COLOR_OPTION_INFO))
      logTextPanel.setTextColor(Priority.INFO,value);
    if (option.equalsIgnoreCase(COLOR_OPTION_DEBUG))
      logTextPanel.setTextColor(Priority.DEBUG,value);
    if (option.equalsIgnoreCase(COLOR_OPTION_BACKGROUND))
      logTextPanel.setTextBackground(value);
    if (option.equalsIgnoreCase(FONT_SIZE_OPTION))
      logTextPanel.setTextFontSize(Integer.parseInt(value));
    if (option.equalsIgnoreCase(FONT_NAME_OPTION))
      logTextPanel.setTextFontName(value);
    if (option.equalsIgnoreCase(EVENT_BUFFER_SIZE_OPTION))
      logTextPanel.setEventBufferSize(Integer.parseInt(value));
    return;