Apache Log4cxx  Version 1.1.0
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>
23 #include <thread>
24 #include <condition_variable>
25 
26 namespace log4cxx
27 {
28 
29 namespace net
30 {
31 
35 class LOG4CXX_EXPORT SocketAppenderSkeleton : public AppenderSkeleton
36 {
37  protected:
38  struct SocketAppenderSkeletonPriv;
39 
40  public:
41  SocketAppenderSkeleton(int defaultPort, int reconnectionDelay);
43 
47  SocketAppenderSkeleton(helpers::InetAddressPtr address, int port, int reconnectionDelay);
48 
52  SocketAppenderSkeleton(const LogString& host, int port, int reconnectionDelay);
53 
57  void activateOptions(helpers::Pool& p) override;
58 
59  void close() override;
60 
61 
67  bool requiresLayout() const override
68  {
69  return false;
70  }
71 
77  void setRemoteHost(const LogString& host);
78 
82  const LogString& getRemoteHost() const;
83 
88  void setPort(int port1);
89 
93  int getPort() const;
94 
100  void setLocationInfo(bool locationInfo1);
101 
105  bool getLocationInfo() const;
106 
116  void setReconnectionDelay(int reconnectionDelay1);
117 
121  int getReconnectionDelay() const;
122 
124 
125  void setOption(const LogString& option, const LogString& value) override;
126 
127  protected:
128  SocketAppenderSkeleton(std::unique_ptr<SocketAppenderSkeletonPriv> priv);
129 
130  virtual void setSocket(log4cxx::helpers::SocketPtr& socket, log4cxx::helpers::Pool& p) = 0;
131 
132  virtual void cleanUp(log4cxx::helpers::Pool& p) = 0;
133 
134  virtual int getDefaultDelay() const = 0;
135 
136  virtual int getDefaultPort() const = 0;
137 
138  private:
139  void connect(log4cxx::helpers::Pool& p);
150  void monitor();
151  bool is_closed();
154 
155 }; // class SocketAppenderSkeleton
156 } // namespace net
157 } // namespace log4cxx
158 
159 #endif // _LOG4CXX_NET_SOCKET_APPENDER_SKELETON_H
160 
Implementation base class for all appenders.
Definition: appenderskeleton.h:41
Definition: pool.h:33
Abstract base class for SocketAppender and XMLSocketAppender.
Definition: socketappenderskeleton.h:36
virtual void cleanUp(log4cxx::helpers::Pool &p)=0
void close() override
Release any resources allocated within the appender such as file handles, network connections,...
SocketAppenderSkeleton(int defaultPort, int reconnectionDelay)
bool requiresLayout() const override
This appender does not use a layout.
Definition: socketappenderskeleton.h:67
SocketAppenderSkeleton(std::unique_ptr< SocketAppenderSkeletonPriv > priv)
SocketAppenderSkeleton(const LogString &host, int port, int reconnectionDelay)
Connects to remote server at host and port.
bool getLocationInfo() const
Returns value of the LocationInfo option.
int getReconnectionDelay() const
Returns value of the ReconnectionDelay option.
SocketAppenderSkeleton(helpers::InetAddressPtr address, int port, int reconnectionDelay)
Connects to remote server at address and port.
void setPort(int port1)
The Port option takes a positive integer representing the port where the server is waiting for connec...
const LogString & getRemoteHost() const
Returns value of the RemoteHost option.
int getPort() const
Returns value of the Port option.
void setReconnectionDelay(int reconnectionDelay1)
The ReconnectionDelay option takes a positive integer representing the number of milliseconds to wait...
void setRemoteHost(const LogString &host)
The RemoteHost option takes a string value which should be the host name of the server where a Apache...
void activateOptions(helpers::Pool &p) override
Connect to the specified RemoteHost and Port.
void setOption(const LogString &option, const LogString &value) override
Set option to value.
virtual int getDefaultDelay() const =0
virtual void setSocket(log4cxx::helpers::SocketPtr &socket, log4cxx::helpers::Pool &p)=0
void setLocationInfo(bool locationInfo1)
The LocationInfo option takes a boolean value.
virtual int getDefaultPort() const =0
Definition: appender.h:27
std::basic_string< logchar > LogString
Definition: logstring.h:60