Coverage Report

Created: 2025-10-13 07:02

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