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.classic.net;
16
17 import java.net.InetAddress;
18
19 import ch.qos.logback.classic.spi.ILoggingEvent;
20 import ch.qos.logback.core.net.SocketAppenderBase;
21 import ch.qos.logback.core.spi.PreSerializationTransformer;
22
23 /**
24 * Sends {@link ILoggingEvent} objects to a remote a log server, usually a
25 * {@link SocketNode}.
26 *
27 * For more information on this appender, please refer to the online manual
28 * at http://logback.qos.ch/manual/appenders.html#SocketAppender
29 *
30 * @author Ceki Gülcü
31 * @author Sébastien Pennec
32 */
33
34 public class SocketAppender extends SocketAppenderBase<ILoggingEvent> {
35
36 boolean includeCallerData = false;
37
38 PreSerializationTransformer<ILoggingEvent> pst = new LoggingEventPreSerializationTransformer();
39
40 public SocketAppender() {
41 }
42
43 /**
44 * Connects to remote server at <code>address</code> and <code>port</code>.
45 */
46 public SocketAppender(InetAddress address, int port) {
47 this.address = address;
48 this.remoteHost = address.getHostName();
49 this.port = port;
50 }
51
52 /**
53 * Connects to remote server at <code>host</code> and <code>port</code>.
54 */
55 public SocketAppender(String host, int port) {
56 this.port = port;
57 this.address = getAddressByName(host);
58 this.remoteHost = host;
59 }
60
61 @Override
62 protected void postProcessEvent(ILoggingEvent event) {
63 if (includeCallerData) {
64 event.getCallerData();
65 }
66 }
67
68 public void setIncludeCallerData(boolean includeCallerData) {
69 this.includeCallerData = includeCallerData;
70 }
71
72 public PreSerializationTransformer<ILoggingEvent> getPST() {
73 return pst;
74 }
75
76 }