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

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

Add 3rd party libraries (log4cxx).

File size: 6.2 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_XML_SOCKET_APPENDER_H
19#define _LOG4CXX_NET_XML_SOCKET_APPENDER_H
20
21#include <log4cxx/net/socketappenderskeleton.h>
22#include <log4cxx/helpers/writer.h>
23
24namespace log4cxx
25{
26 namespace net
27 {
28
29 /**
30 Sends {@link log4cxx::spi::LoggingEvent LoggingEvent} objects in XML format
31 to a remote a log server, usually a XMLSocketNode.
32
33 <p>The XMLSocketAppender has the following properties:
34
35 - If sent to a XMLSocketNode, 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 - XMLSocketAppenders use exclusively an XMLLayout. They ship an
42 XML stream representing a {@link 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 an <code>XMLSocketAppender</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>XMLSocketAppender</code> explicitly. See also next item.
73 @n @n Long lived applications which create/destroy many
74 <code>XMLSocketAppender</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>XMLSocketAppender</code>
79 exits before the <code>XMLSocketAppender</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>XMLSocketAppender</code> either explicitly or by
84 calling the LogManager#shutdown method
85 before exiting the application.
86 */
87
88 class LOG4CXX_EXPORT XMLSocketAppender : 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 /**
102 An event XML stream cannot exceed 1024 bytes.
103 */
104 static const int MAX_EVENT_LEN;
105
106 DECLARE_LOG4CXX_OBJECT(XMLSocketAppender)
107 BEGIN_LOG4CXX_CAST_MAP()
108 LOG4CXX_CAST_ENTRY(XMLSocketAppender)
109 LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
110 END_LOG4CXX_CAST_MAP()
111
112 XMLSocketAppender();
113 ~XMLSocketAppender();
114
115 /**
116 Connects to remote server at <code>address</code> and <code>port</code>.
117 */
118 XMLSocketAppender(helpers::InetAddressPtr address, int port);
119
120 /**
121 Connects to remote server at <code>host</code> and <code>port</code>.
122 */
123 XMLSocketAppender(const LogString& host, int port);
124
125
126 protected:
127 virtual void setSocket(log4cxx::helpers::SocketPtr& socket, log4cxx::helpers::Pool& p);
128
129 virtual void cleanUp(log4cxx::helpers::Pool& p);
130
131 virtual int getDefaultDelay() const;
132
133 virtual int getDefaultPort() const;
134
135 void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& pool);
136
137 private:
138 log4cxx::helpers::WriterPtr writer;
139 // prevent copy and assignment statements
140 XMLSocketAppender(const XMLSocketAppender&);
141 XMLSocketAppender& operator=(const XMLSocketAppender&);
142 }; // class XMLSocketAppender
143
144 LOG4CXX_PTR_DEF(XMLSocketAppender);
145
146 } // namespace net
147} // namespace log4cxx
148
149#endif // _LOG4CXX_NET_XML_SOCKET_APPENDER_H
150
Note: See TracBrowser for help on using the repository browser.