source: pacpusframework/trunk/3rd/apache-log4cxx/include/log4cxx/net/socketappender.h@ 19

Last change on this file since 19 was 2, checked in by sgosseli, 12 years ago

Add 3rd party libraries (log4cxx).

File size: 5.8 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _LOG4CXX_NET_SOCKET_APPENDER_H
19#define _LOG4CXX_NET_SOCKET_APPENDER_H
20
21#include <log4cxx/net/socketappenderskeleton.h>
22#include <log4cxx/helpers/objectoutputstream.h>
23
24namespace log4cxx
25{
26 namespace net
27 {
28
29 /**
30 Sends {@link log4cxx::spi::LoggingEvent LoggingEvent} objects to a remote a log server,
31 usually Apache Chainsaw.
32
33 <p>The SocketAppender has the following properties:
34
35 - If sent to Apache Chainsaw, remote logging
36 is non-intrusive as far as the log event is concerned. In other
37 words, the event will be logged with the same time stamp, {@link
38 NDC NDC}, location info as if it were logged locally by
39 the client.
40
41 - SocketAppenders do not use a layout. They ship a
42 serialized {@link log4cxx::spi::LoggingEvent LoggingEvent} object
43 to the server side.
44
45 - Remote logging uses the TCP protocol. Consequently, if
46 the server is reachable, then log events will eventually arrive
47 at the server.
48
49 - If the remote server is down, the logging requests are
50 simply dropped. However, if and when the server comes back up,
51 then event transmission is resumed transparently. This
52 transparent reconneciton is performed by a <em>connector</em>
53 thread which periodically attempts to connect to the server.
54
55 - Logging events are automatically <em>buffered</em> by the
56 native TCP implementation. This means that if the link to server
57 is slow but still faster than the rate of (log) event production
58 by the client, the client will not be affected by the slow
59 network connection. However, if the network connection is slower
60 then the rate of event production, then the client can only
61 progress at the network rate. In particular, if the network link
62 to the the server is down, the client will be blocked.
63 @n @n On the other hand, if the network link is up, but the server
64 is down, the client will not be blocked when making log requests
65 but the log events will be lost due to server unavailability.
66
67 - Even if a <code>SocketAppender</code> is no longer
68 attached to any logger, it will not be destroyed in
69 the presence of a connector thread. A connector thread exists
70 only if the connection to the server is down. To avoid this
71 destruction problem, you should #close the the
72 <code>SocketAppender</code> explicitly. See also next item.
73 @n @n Long lived applications which create/destroy many
74 <code>SocketAppender</code> instances should be aware of this
75 destruction problem. Most other applications can safely
76 ignore it.
77
78 - If the application hosting the <code>SocketAppender</code>
79 exits before the <code>SocketAppender</code> is closed either
80 explicitly or subsequent to destruction, then there might
81 be untransmitted data in the pipe which might be lost.
82 @n @n To avoid lost data, it is usually sufficient to
83 #close the <code>SocketAppender</code> either explicitly or by
84 calling the LogManager#shutdown method
85 before exiting the application.
86 */
87
88 class LOG4CXX_EXPORT SocketAppender : public SocketAppenderSkeleton
89 {
90 public:
91 /**
92 The default port number of remote logging server (4560).
93 */
94 static int DEFAULT_PORT;
95
96 /**
97 The default reconnection delay (30000 milliseconds or 30 seconds).
98 */
99 static int DEFAULT_RECONNECTION_DELAY;
100
101 DECLARE_LOG4CXX_OBJECT(SocketAppender)
102 BEGIN_LOG4CXX_CAST_MAP()
103 LOG4CXX_CAST_ENTRY(SocketAppender)
104 LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
105 END_LOG4CXX_CAST_MAP()
106
107 SocketAppender();
108 ~SocketAppender();
109
110 /**
111 Connects to remote server at <code>address</code> and <code>port</code>.
112 */
113 SocketAppender(helpers::InetAddressPtr& address, int port);
114
115 /**
116 Connects to remote server at <code>host</code> and <code>port</code>.
117 */
118 SocketAppender(const LogString& host, int port);
119
120
121 protected:
122 virtual void setSocket(log4cxx::helpers::SocketPtr& socket, log4cxx::helpers::Pool& p);
123
124 virtual void cleanUp(log4cxx::helpers::Pool& p);
125
126 virtual int getDefaultDelay() const;
127
128 virtual int getDefaultPort() const;
129
130 void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& pool);
131
132 private:
133 log4cxx::helpers::ObjectOutputStreamPtr oos;
134
135 }; // class SocketAppender
136
137 LOG4CXX_PTR_DEF(SocketAppender);
138
139 } // namespace net
140} // namespace log4cxx
141
142#endif // _LOG4CXX_NET_SOCKET_APPENDER_H
143
Note: See TracBrowser for help on using the repository browser.