View Javadoc

1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 1999-2006, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  
11  // Contributors: Dan MacDonald <dan@redknee.com>
12  package ch.qos.logback.classic.net;
13  
14  import java.net.InetAddress;
15  
16  import ch.qos.logback.classic.spi.LoggingEvent;
17  import ch.qos.logback.core.net.SocketAppenderBase;
18  
19  /**
20   * Sends {@link LoggingEvent} objects to a remote a log server, usually a
21   * {@link SocketNode}.
22   * 
23   * For more information on this appender, please refer to the online manual
24   * at http://logback.qos.ch/manual/appenders.html#SocketAppender
25   * 
26   * @author Ceki G&uuml;lc&uuml;
27   * @author S&eacute;bastien Pennec
28   */
29  
30  public class SocketAppender extends SocketAppenderBase<LoggingEvent> {
31  
32    boolean includeCallerData = false;
33  
34    public SocketAppender() {
35    }
36  
37    /**
38     * Connects to remote server at <code>address</code> and <code>port</code>.
39     */
40    public SocketAppender(InetAddress address, int port) {
41      this.address = address;
42      this.remoteHost = address.getHostName();
43      this.port = port;
44    }
45  
46    /**
47     * Connects to remote server at <code>host</code> and <code>port</code>.
48     */
49    public SocketAppender(String host, int port) {
50      this.port = port;
51      this.address = getAddressByName(host);
52      this.remoteHost = host;
53    }
54  
55    @Override
56    protected void postProcessEvent(LoggingEvent event) {
57      if (includeCallerData) {
58        event.getCallerData();
59      }
60    }
61  
62    public void setIncludeCallerData(boolean includeCallerData) {
63      this.includeCallerData = includeCallerData;
64    }
65  
66  }