/src/logging-log4cxx/src/main/include/log4cxx/net/telnetappender.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_TELNET_APPENDER_H |
19 | | #define _LOG4CXX_NET_TELNET_APPENDER_H |
20 | | |
21 | | #include <log4cxx/appenderskeleton.h> |
22 | | #include <log4cxx/helpers/socket.h> |
23 | | |
24 | | namespace LOG4CXX_NS |
25 | | { |
26 | | namespace helpers |
27 | | { |
28 | | class ByteBuffer; |
29 | | } |
30 | | namespace net |
31 | | { |
32 | | |
33 | | /** |
34 | | The TelnetAppender writes log messages to |
35 | | clients that connect to the TCP port. |
36 | | |
37 | | This allows logging output to be monitored using TCP/IP. |
38 | | To receive log data, use telnet to connect to the configured port number. |
39 | | |
40 | | TelnetAppender is most useful as a secondary appender, |
41 | | especially when monitoring a servlet remotely. |
42 | | |
43 | | If no layout is provided, the log message only is sent to attached client(s). |
44 | | |
45 | | The \c ReuseAddress option is disabled by default. |
46 | | Enable it to be able to connect to this appender |
47 | | immediately after the logging process restarts. |
48 | | |
49 | | See TelnetAppender::setOption() for the available options. |
50 | | |
51 | | */ |
52 | | class LOG4CXX_EXPORT TelnetAppender : public AppenderSkeleton |
53 | | { |
54 | | private: |
55 | | static const int DEFAULT_PORT; |
56 | | static const int MAX_CONNECTIONS; |
57 | | |
58 | | public: |
59 | | DECLARE_LOG4CXX_OBJECT(TelnetAppender) |
60 | 0 | BEGIN_LOG4CXX_CAST_MAP() |
61 | 0 | LOG4CXX_CAST_ENTRY(TelnetAppender) |
62 | 0 | LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) |
63 | 0 | END_LOG4CXX_CAST_MAP() |
64 | | |
65 | | TelnetAppender(); |
66 | | ~TelnetAppender(); |
67 | | |
68 | | /** |
69 | | If no layout is provided, sends only the log message to attached client(s). |
70 | | */ |
71 | | bool requiresLayout() const override; |
72 | | |
73 | | /** |
74 | | The current encoding value. |
75 | | |
76 | | \sa setOption |
77 | | */ |
78 | | LogString getEncoding() const; |
79 | | /** |
80 | | Set the encoding to \c value. |
81 | | |
82 | | \sa setOption |
83 | | */ |
84 | | void setEncoding(const LogString& value); |
85 | | |
86 | | |
87 | | using AppenderSkeleton::activateOptions; |
88 | | /** |
89 | | \copybrief AppenderSkeleton::activateOptions() |
90 | | |
91 | | Create the socket handler and wait for connections. |
92 | | */ |
93 | | void activateOptions( LOG4CXX_ACTIVATE_OPTIONS_FORMAL_PARAMETERS ) override; |
94 | | |
95 | | |
96 | | /** |
97 | | \copybrief AppenderSkeleton::setOption() |
98 | | |
99 | | Supported options | Supported values | Default value | |
100 | | -------------- | ---------------- | --------------- | |
101 | | Port | {int} | 23 | |
102 | | Hostname | name or numeric address | - | |
103 | | MaxConnections | {int} | 20 | |
104 | | Encoding | C,UTF-8,UTF-16,UTF-16BE,UTF-16LE,646,US-ASCII,ISO646-US,ANSI_X3.4-1968,ISO-8859-1,ISO-LATIN-1 | UTF-8 | |
105 | | ReuseAddress | True,False | False | |
106 | | NonBlocking | True,False | False | |
107 | | |
108 | | \sa AppenderSkeleton::setOption() |
109 | | */ |
110 | | void setOption(const LogString& option, const LogString& value) override; |
111 | | |
112 | | /** |
113 | | The TCP <b>Port</b> number on which to accept connections. |
114 | | */ |
115 | | int getPort() const; |
116 | | |
117 | | /** |
118 | | Use \c newValue as the TCP port number on which to accept connections. |
119 | | */ |
120 | | void setPort(int newValue); |
121 | | |
122 | | /** |
123 | | The <b>Hostname</b> on which to accept connections. |
124 | | */ |
125 | | LogString getHostname() const; |
126 | | |
127 | | /** |
128 | | Use \c newValue as the Hostname on which to accept connections. |
129 | | By default connections are accepted on any network interface device. |
130 | | */ |
131 | | void setHostname(const LogString& newValue); |
132 | | |
133 | | /** |
134 | | The number of allowed concurrent connections. |
135 | | |
136 | | \sa setOption |
137 | | */ |
138 | | int getMaxConnections() const; |
139 | | |
140 | | /** |
141 | | Set the number of allowed concurrent connections to \c newValue. |
142 | | |
143 | | \sa setOption |
144 | | */ |
145 | | void setMaxConnections(int newValue); |
146 | | |
147 | | /** |
148 | | Use \c newValue for the SO_REUSEADDR option of the socket accepting connections. |
149 | | When set to \c true, a telnet client can connect when the socket is in a TIME_WAIT state, |
150 | | so log message delivery will resume quickly when a terminated process restarts. |
151 | | |
152 | | \sa setOption |
153 | | */ |
154 | | void setReuseAddress(bool newValue); |
155 | | |
156 | | /** |
157 | | Use \c newValue for the behaviour when the TCP send buffer (on an accepted socket connection) is full. |
158 | | |
159 | | When true, the socket connection is closed if the write would block. |
160 | | |
161 | | \sa setOption |
162 | | */ |
163 | | void setNonBlocking(bool newValue); |
164 | | |
165 | | /** Shutdown this appender. */ |
166 | | void close() override; |
167 | | |
168 | | protected: |
169 | | /** Send \c event to each connected client. |
170 | | */ |
171 | | void append( LOG4CXX_APPEND_FORMAL_PARAMETERS ) override; |
172 | | |
173 | | private: |
174 | | // prevent copy and assignment statements |
175 | | TelnetAppender(const TelnetAppender&); |
176 | | TelnetAppender& operator=(const TelnetAppender&); |
177 | | |
178 | | void write(helpers::ByteBuffer&); |
179 | | void writeStatus(const helpers::SocketPtr& socket, const LogString& msg, helpers::Pool& p); |
180 | | void acceptConnections(); |
181 | | |
182 | | struct TelnetAppenderPriv; |
183 | | }; // class TelnetAppender |
184 | | |
185 | | LOG4CXX_PTR_DEF(TelnetAppender); |
186 | | } // namespace net |
187 | | } // namespace log4cxx |
188 | | |
189 | | #endif // _LOG4CXX_NET_TELNET_APPENDER_H |
190 | | |