View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  // Contributors: Dan MacDonald <dan@redknee.com>
15  package ch.qos.logback.access.net;
16  
17  import java.net.InetAddress;
18  
19  import ch.qos.logback.access.spi.AccessEvent;
20  import ch.qos.logback.core.net.SocketAppenderBase;
21  import ch.qos.logback.core.spi.PreSerializationTransformer;
22  
23  /**
24   * Sends {@link AccessEvent} objects to a remote a log server, usually a
25   * {@link SocketNode}.
26   * 
27   * For more information about this appender, please refer to the online manual at
28   * http://logback.qos.ch/manual/appenders.html#AccessSocketAppender
29   *  
30   * @author Ceki G&uuml;lc&uuml;
31   * @author S&eacute;bastien Pennec
32   * 
33   */
34  
35  public class SocketAppender extends SocketAppenderBase<AccessEvent> {
36    
37    PreSerializationTransformer<AccessEvent> pst = new AccessEventPreSerializationTransformer();
38    
39    public SocketAppender() {
40    }
41  
42    /**
43     * Connects to remote server at <code>address</code> and <code>port</code>.
44     */
45    public SocketAppender(InetAddress address, int port) {
46      this.address = address;
47      this.remoteHost = address.getHostName();
48      this.port = port;
49    }
50  
51    /**
52     * Connects to remote server at <code>host</code> and <code>port</code>.
53     */
54    public SocketAppender(String host, int port) {
55      this.port = port;
56      this.address = getAddressByName(host);
57      this.remoteHost = host;
58    }
59    
60    @Override
61    protected void postProcessEvent(AccessEvent event) {
62      AccessEvent ae = (AccessEvent)event;
63      ae.prepareForDeferredProcessing();
64    }
65  
66    public PreSerializationTransformer<AccessEvent> getPST() {
67      return pst;
68    }
69  }