/src/logging-log4cxx/src/main/include/log4cxx/net/xmlsocketappender.h
Line | Count | Source |
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 | | |
23 | | namespace LOG4CXX_NS |
24 | | { |
25 | | namespace net |
26 | | { |
27 | | |
28 | | /** |
29 | | Sends spi::LoggingEvent elements |
30 | | to a remote a log server, usually in XML format. |
31 | | |
32 | | Here is an example configuration that writes JSON to the |
33 | | <a href="https://docs.fluentbit.io/manual/pipeline/inputs/tcp">TCP input plugin of a fluent-bit log server</a> |
34 | | running on the same system as the application: |
35 | | ~~~{.xml} |
36 | | <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
37 | | <appender name="A1" class="XMLSocketAppender"> |
38 | | <param name="RemoteHost" value="localhost" /> |
39 | | <param name="Port" value="5170" /> |
40 | | <layout class="JSONLayout"/> |
41 | | </appender> |
42 | | <root> |
43 | | <priority value ="INFO" /> |
44 | | <appender-ref ref="A1" /> |
45 | | </root> |
46 | | </log4j:configuration> |
47 | | ~~~ |
48 | | |
49 | | See \ref socket_appender_properties "SocketAppenderSkeleton" for more information on the behaviour this appender. |
50 | | */ |
51 | | |
52 | | class LOG4CXX_EXPORT XMLSocketAppender : public SocketAppenderSkeleton |
53 | | { |
54 | | public: |
55 | | /** |
56 | | The default port number of remote logging server (4560). |
57 | | */ |
58 | | static int DEFAULT_PORT; |
59 | | |
60 | | /** |
61 | | The default reconnection delay (30000 milliseconds or 30 seconds). |
62 | | */ |
63 | | static int DEFAULT_RECONNECTION_DELAY; |
64 | | |
65 | | #if LOG4CXX_ABI_VERSION <= 15 |
66 | | /** |
67 | | Unused |
68 | | */ |
69 | | static const int MAX_EVENT_LEN; |
70 | | #endif |
71 | | |
72 | | DECLARE_LOG4CXX_OBJECT(XMLSocketAppender) |
73 | 0 | BEGIN_LOG4CXX_CAST_MAP() |
74 | 0 | LOG4CXX_CAST_ENTRY(XMLSocketAppender) |
75 | 0 | LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) |
76 | 0 | END_LOG4CXX_CAST_MAP() |
77 | | |
78 | | XMLSocketAppender(); |
79 | | ~XMLSocketAppender(); |
80 | | |
81 | | /** |
82 | | Connects to remote server at <code>address</code> and <code>port</code>. |
83 | | */ |
84 | | #if LOG4CXX_ABI_VERSION <= 15 |
85 | | XMLSocketAppender(helpers::InetAddressPtr address, int port); |
86 | | #else |
87 | | XMLSocketAppender(const helpers::InetAddressPtr& address, int port); |
88 | | #endif |
89 | | |
90 | | /** |
91 | | Connects to remote server at <code>host</code> and <code>port</code>. |
92 | | */ |
93 | | XMLSocketAppender(const LogString& host, int port); |
94 | | |
95 | | using SocketAppenderSkeleton::activateOptions; |
96 | | |
97 | | #if 15 < LOG4CXX_ABI_VERSION |
98 | | /** |
99 | | * This appender has a default layout. |
100 | | * @returns false |
101 | | */ |
102 | | bool requiresLayout() const override |
103 | | { |
104 | | return false; |
105 | | } |
106 | | #endif |
107 | | |
108 | | protected: |
109 | | #if LOG4CXX_ABI_VERSION <= 15 |
110 | | /** |
111 | | @deprecated This method will be removed in a future version. |
112 | | */ |
113 | | void setSocket(LOG4CXX_NS::helpers::SocketPtr& socket, helpers::Pool& p) override; |
114 | | |
115 | | /** |
116 | | @deprecated This method will be removed in a future version. |
117 | | */ |
118 | | void cleanUp(helpers::Pool& p) override; |
119 | | #endif |
120 | | int getDefaultDelay() const override; |
121 | | |
122 | | int getDefaultPort() const override; |
123 | | |
124 | | void append( LOG4CXX_APPEND_FORMAL_PARAMETERS ) override; |
125 | | |
126 | | private: |
127 | | // prevent copy and assignment statements |
128 | | XMLSocketAppender(const XMLSocketAppender&); |
129 | | XMLSocketAppender& operator=(const XMLSocketAppender&); |
130 | | |
131 | | #if LOG4CXX_ABI_VERSION <= 15 |
132 | | struct XMLSocketAppenderPriv; |
133 | | #endif |
134 | | }; // class XMLSocketAppender |
135 | | |
136 | | LOG4CXX_PTR_DEF(XMLSocketAppender); |
137 | | |
138 | | } // namespace net |
139 | | } // namespace log4cxx |
140 | | |
141 | | #endif // _LOG4CXX_NET_XML_SOCKET_APPENDER_H |
142 | | |