Apache log4cxx  Version 0.12.1
socketappenderskeleton.h
Go to the documentation of this file.
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_SOCKET_APPENDER_SKELETON_H
19 #define _LOG4CXX_NET_SOCKET_APPENDER_SKELETON_H
20 
22 #include <log4cxx/helpers/socket.h>
24 #include <thread>
25 #include <condition_variable>
26 
27 #if defined(_MSC_VER)
28  #pragma warning ( push )
29  #pragma warning ( disable: 4251 )
30 #endif
31 
32 namespace log4cxx
33 {
34 
35 namespace net
36 {
37 
41 class LOG4CXX_EXPORT SocketAppenderSkeleton : public AppenderSkeleton
42 {
43  private:
47  LogString remoteHost;
48 
52  helpers::InetAddressPtr address;
53 
54  int port;
55  int reconnectionDelay;
56  bool locationInfo;
57 
58  public:
59  SocketAppenderSkeleton(int defaultPort, int reconnectionDelay);
61 
65  SocketAppenderSkeleton(helpers::InetAddressPtr address, int port, int reconnectionDelay);
66 
70  SocketAppenderSkeleton(const LogString& host, int port, int reconnectionDelay);
71 
75  void activateOptions(log4cxx::helpers::Pool& p);
76 
77  void close();
78 
79 
85  bool requiresLayout() const
86  {
87  return false;
88  }
89 
95  inline void setRemoteHost(const LogString& host)
96  {
97  address = helpers::InetAddress::getByName(host);
98  remoteHost.assign(host);
99  }
100 
104  inline const LogString& getRemoteHost() const
105  {
106  return remoteHost;
107  }
108 
113  void setPort(int port1)
114  {
115  this->port = port1;
116  }
117 
121  int getPort() const
122  {
123  return port;
124  }
125 
131  void setLocationInfo(bool locationInfo1)
132  {
133  this->locationInfo = locationInfo1;
134  }
135 
139  bool getLocationInfo() const
140  {
141  return locationInfo;
142  }
143 
153  void setReconnectionDelay(int reconnectionDelay1)
154  {
155  this->reconnectionDelay = reconnectionDelay1;
156  }
157 
162  {
163  return reconnectionDelay;
164  }
165 
166  void fireConnector();
167 
168  void setOption(const LogString& option,
169  const LogString& value);
170 
171  protected:
172 
173  virtual void setSocket(log4cxx::helpers::SocketPtr& socket, log4cxx::helpers::Pool& p) = 0;
174 
175  virtual void cleanUp(log4cxx::helpers::Pool& p) = 0;
176 
177  virtual int getDefaultDelay() const = 0;
178 
179  virtual int getDefaultPort() const = 0;
180 
181  private:
182  void connect(log4cxx::helpers::Pool& p);
193  std::thread thread;
194  std::condition_variable interrupt;
195  std::mutex interrupt_mutex;
196  void monitor();
197  bool is_closed();
200 
201 }; // class SocketAppenderSkeleton
202 } // namespace net
203 } // namespace log4cxx
204 
205 #if defined(_MSC_VER)
206  #pragma warning (pop)
207 #endif
208 
209 #endif // _LOG4CXX_NET_SOCKET_APPENDER_SKELETON_H
210 
int getReconnectionDelay() const
Returns value of the ReconnectionDelay option.
Definition: socketappenderskeleton.h:161
Implementation base class for all appenders.
Definition: appenderskeleton.h:43
void setPort(int port1)
The Port option takes a positive integer representing the port where the server is waiting for connec...
Definition: socketappenderskeleton.h:113
bool getLocationInfo() const
Returns value of the LocationInfo option.
Definition: socketappenderskeleton.h:139
Abstract base class for SocketAppender and XMLSocketAppender.
Definition: socketappenderskeleton.h:41
void setRemoteHost(const LogString &host)
The RemoteHost option takes a string value which should be the host name of the server where a Apache...
Definition: socketappenderskeleton.h:95
int getPort() const
Returns value of the Port option.
Definition: socketappenderskeleton.h:121
void setReconnectionDelay(int reconnectionDelay1)
The ReconnectionDelay option takes a positive integer representing the number of milliseconds to wait...
Definition: socketappenderskeleton.h:153
Definition: pool.h:32
static InetAddressPtr getByName(const LogString &host)
Determines the IP address of a host, given the host&#39;s name.
const LogString & getRemoteHost() const
Returns value of the RemoteHost option.
Definition: socketappenderskeleton.h:104
bool requiresLayout() const
This appender does not use a layout.
Definition: socketappenderskeleton.h:85
void setLocationInfo(bool locationInfo1)
The LocationInfo option takes a boolean value.
Definition: socketappenderskeleton.h:131
Definition: appender.h:32
std::basic_string< logchar > LogString
Definition: logstring.h:66