Apache log4cxx  Version 0.11.0
socketappenderskeleton.h
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 
21 #include <log4cxx/appenderskeleton.h>
22 #include <log4cxx/helpers/socket.h>
23 #include <log4cxx/helpers/thread.h>
24 #include <log4cxx/helpers/objectoutputstream.h>
25 
26 #if defined(_MSC_VER)
27  #pragma warning ( push )
28  #pragma warning ( disable: 4251 )
29 #endif
30 
31 namespace log4cxx
32 {
33 
34 namespace net
35 {
36 
40 class LOG4CXX_EXPORT SocketAppenderSkeleton : public AppenderSkeleton
41 {
42  private:
46  LogString remoteHost;
47 
51  helpers::InetAddressPtr address;
52 
53  int port;
54  int reconnectionDelay;
55  bool locationInfo;
56 
57  public:
58  SocketAppenderSkeleton(int defaultPort, int reconnectionDelay);
60 
64  SocketAppenderSkeleton(helpers::InetAddressPtr address, int port, int reconnectionDelay);
65 
69  SocketAppenderSkeleton(const LogString& host, int port, int reconnectionDelay);
70 
74  void activateOptions(log4cxx::helpers::Pool& p);
75 
76  void close();
77 
78 
84  bool requiresLayout() const
85  {
86  return false;
87  }
88 
94  inline void setRemoteHost(const LogString& host)
95  {
96  address = helpers::InetAddress::getByName(host);
97  remoteHost.assign(host);
98  }
99 
103  inline const LogString& getRemoteHost() const
104  {
105  return remoteHost;
106  }
107 
112  void setPort(int port1)
113  {
114  this->port = port1;
115  }
116 
120  int getPort() const
121  {
122  return port;
123  }
124 
130  void setLocationInfo(bool locationInfo1)
131  {
132  this->locationInfo = locationInfo1;
133  }
134 
138  bool getLocationInfo() const
139  {
140  return locationInfo;
141  }
142 
152  void setReconnectionDelay(int reconnectionDelay1)
153  {
154  this->reconnectionDelay = reconnectionDelay1;
155  }
156 
161  {
162  return reconnectionDelay;
163  }
164 
165  void fireConnector();
166 
167  void setOption(const LogString& option,
168  const LogString& value);
169 
170  protected:
171 
172  virtual void setSocket(log4cxx::helpers::SocketPtr& socket, log4cxx::helpers::Pool& p) = 0;
173 
174  virtual void cleanUp(log4cxx::helpers::Pool& p) = 0;
175 
176  virtual int getDefaultDelay() const = 0;
177 
178  virtual int getDefaultPort() const = 0;
179 
180  private:
181  void connect(log4cxx::helpers::Pool& p);
192  helpers::Thread thread;
193  static void* LOG4CXX_THREAD_FUNC monitor(apr_thread_t* thread, void* data);
196 
197 }; // class SocketAppenderSkeleton
198 } // namespace net
199 } // namespace log4cxx
200 
201 #if defined(_MSC_VER)
202  #pragma warning (pop)
203 #endif
204 
205 #endif // _LOG4CXX_NET_SOCKET_APPENDER_SKELETON_H
206 
This class implements an approximation of java.util.Thread.
Definition: thread.h:59
int getReconnectionDelay() const
Returns value of the ReconnectionDelay option.
Definition: socketappenderskeleton.h:160
Implementation base class for all appenders.
Definition: appenderskeleton.h:45
void setPort(int port1)
The Port option takes a positive integer representing the port where the server is waiting for connec...
Definition: socketappenderskeleton.h:112
bool getLocationInfo() const
Returns value of the LocationInfo option.
Definition: socketappenderskeleton.h:138
Abstract base class for SocketAppender and XMLSocketAppender.
Definition: socketappenderskeleton.h:40
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:94
int getPort() const
Returns value of the Port option.
Definition: socketappenderskeleton.h:120
void setReconnectionDelay(int reconnectionDelay1)
The ReconnectionDelay option takes a positive integer representing the number of milliseconds to wait...
Definition: socketappenderskeleton.h:152
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:103
bool requiresLayout() const
This appender does not use a layout.
Definition: socketappenderskeleton.h:84
void setLocationInfo(bool locationInfo1)
The LocationInfo option takes a boolean value.
Definition: socketappenderskeleton.h:130
Definition: appender.h:33