@Override
 protected void append(ILoggingEvent event) {
   if (event == null || !isStarted()) return;
   if (includeCallerData) {
     event.getCallerData();
   }
   super.append(event);
 }
예제 #2
0
  public static void main(String[] args) throws Exception {
    if (args.length != 2) {
      usage("Wrong number of arguments.");
    }

    String hostName = args[0];
    int port = Integer.parseInt(args[1]);

    // Create a SocketAppender connected to hostname:port with a
    // reconnection delay of 10000 seconds.
    SocketAppender socketAppender = new SocketAppender();
    socketAppender.setRemoteHost(hostName);
    socketAppender.setPort(port);
    socketAppender.setReconnectionDelay(10000);
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    socketAppender.setContext(lc);

    // SocketAppender options become active only after the execution
    // of the next statement.
    socketAppender.start();

    Logger logger = (Logger) LoggerFactory.getLogger(SocketClient1.class);
    logger.addAppender(socketAppender);

    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    while (true) {
      System.out.println(
          "Type a message to send to log server at "
              + hostName
              + ":"
              + port
              + ". Type 'q' to quit.");

      String s = reader.readLine();

      if (s.equals("q")) {
        break;
      } else {
        logger.debug(s);
      }
    }
  }