/src/logging-log4cxx/src/main/include/log4cxx/net/telnetappender.h
Line | Count | Source (jump to first uncovered 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_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 | | /** |
88 | | \copybrief AppenderSkeleton::activateOptions() |
89 | | |
90 | | Create the socket handler and wait for connections. |
91 | | */ |
92 | | void activateOptions(helpers::Pool& p) override; |
93 | | |
94 | | |
95 | | /** |
96 | | \copybrief AppenderSkeleton::setOption() |
97 | | |
98 | | Supported options | Supported values | Default value |
99 | | -------------- | ---------------- | --------------- |
100 | | Port | {int} | 23 |
101 | | MaxConnections | {int} | 20 |
102 | | 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 |
103 | | ReuseAddress | True,False | False |
104 | | |
105 | | \sa AppenderSkeleton::setOption() |
106 | | */ |
107 | | void setOption(const LogString& option, const LogString& value) override; |
108 | | |
109 | | /** |
110 | | The TCP <b>Port</b> number on which to accept connections. |
111 | | */ |
112 | | int getPort() const; |
113 | | |
114 | | /** |
115 | | Use \c newValue as the TCP port number on which to accept connections. |
116 | | */ |
117 | | void setPort(int newValue); |
118 | | |
119 | | /** |
120 | | The <b>Hostname</b> on which to accept connections. |
121 | | */ |
122 | | LogString getHostname() const; |
123 | | |
124 | | /** |
125 | | Use \c newValue as the Hostname on which to accept connections. |
126 | | By default connections are accepted on any network interface device. |
127 | | */ |
128 | | void setHostname(const LogString& newValue); |
129 | | |
130 | | /** |
131 | | The number of allowed concurrent connections. |
132 | | |
133 | | \sa setOption |
134 | | */ |
135 | | int getMaxConnections() const; |
136 | | |
137 | | /** |
138 | | Set the number of allowed concurrent connections to \c newValue. |
139 | | |
140 | | \sa setOption |
141 | | */ |
142 | | void setMaxConnections(int newValue); |
143 | | |
144 | | /** |
145 | | Use \c newValue for the SO_REUSEADDR option of the socket accepting connections. |
146 | | When set to \c true, a telnet client can connect when the socket is in a TIME_WAIT state, |
147 | | so log message delivery will resume quickly when a terminated process restarts. |
148 | | |
149 | | \sa setOption |
150 | | */ |
151 | | void setReuseAddress(bool newValue); |
152 | | |
153 | | /** Shutdown this appender. */ |
154 | | void close() override; |
155 | | |
156 | | protected: |
157 | | /** Send \c event to each connected client. |
158 | | */ |
159 | | void append(const spi::LoggingEventPtr& event, helpers::Pool& p) override; |
160 | | |
161 | | private: |
162 | | // prevent copy and assignment statements |
163 | | TelnetAppender(const TelnetAppender&); |
164 | | TelnetAppender& operator=(const TelnetAppender&); |
165 | | |
166 | | void write(helpers::ByteBuffer&); |
167 | | void writeStatus(const helpers::SocketPtr& socket, const LogString& msg, helpers::Pool& p); |
168 | | void acceptConnections(); |
169 | | |
170 | | struct TelnetAppenderPriv; |
171 | | }; // class TelnetAppender |
172 | | |
173 | | LOG4CXX_PTR_DEF(TelnetAppender); |
174 | | } // namespace net |
175 | | } // namespace log4cxx |
176 | | |
177 | | #endif // _LOG4CXX_NET_TELNET_APPENDER_H |
178 | | |