FileDocCategorySizeDatePackage
TelnetAppender.javaAPI DocApache log4j 1.2.155818Sat Aug 25 00:09:40 BST 2007org.apache.log4j.net

TelnetAppender

public class TelnetAppender extends AppenderSkeleton

The TelnetAppender is a log4j appender that specializes in writing to a read-only socket. The output is provided in a telnet-friendly way so that a log can be monitored over TCP/IP. Clients using telnet connect to the socket and receive log data. This is handy for remote monitoring, especially when monitoring a servlet.

Here is a list of the available configuration options:
Name Requirement Description Sample Value
Port optional This parameter determines the port to use for announcing log events. The default port is 23 (telnet). 5875

author
Jay Funnell

Fields Summary
private SocketHandler
sh
private int
port
Constructors Summary
Methods Summary
public voidactivateOptions()
all of the options have been set, create the socket handler and wait for connections.

    try {
      sh = new SocketHandler(port);
      sh.start();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
    super.activateOptions();
  
protected voidappend(org.apache.log4j.spi.LoggingEvent event)
Handles a log event. For this appender, that means writing the message to each connected client.

    sh.send(this.layout.format(event));
    if(layout.ignoresThrowable()) {
      String[] s = event.getThrowableStrRep();
      if (s != null) {
	int len = s.length;
	for(int i = 0; i < len; i++) {
	  sh.send(s[i]);
	  sh.send(Layout.LINE_SEP);
	}
      }
    }
  
public voidclose()
shuts down the appender.

    if (sh != null) {
        sh.close();
        try {
            sh.join();
        } catch(InterruptedException ex) {
        }
    }
  
public intgetPort()

    return port;
  
public booleanrequiresLayout()
This appender requires a layout to format the text to the attached client(s).


                           
     
    return true;
  
public voidsetPort(int port)

    this.port = port;