Apache Log4cxx  Version 1.3.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>
23 #include <thread>
24 #include <condition_variable>
25 
26 namespace LOG4CXX_NS
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 
59  void activateOptions(helpers::Pool& p) override;
60 
61  void close() override;
62 
63 
69  bool requiresLayout() const override
70  {
71  return false;
72  }
73 
79  void setRemoteHost(const LogString& host);
80 
84  const LogString& getRemoteHost() const;
85 
90  void setPort(int port1);
91 
95  int getPort() const;
96 
102  void setLocationInfo(bool locationInfo1);
103 
107  bool getLocationInfo() const;
108 
118  void setReconnectionDelay(int reconnectionDelay1);
119 
123  int getReconnectionDelay() const;
124 
126 
142  void setOption(const LogString& option, const LogString& value) override;
143 
144  protected:
145  SocketAppenderSkeleton(std::unique_ptr<SocketAppenderSkeletonPriv> priv);
146 
147  virtual void setSocket(LOG4CXX_NS::helpers::SocketPtr& socket, LOG4CXX_NS::helpers::Pool& p) = 0;
148 
149  virtual void cleanUp(LOG4CXX_NS::helpers::Pool& p) = 0;
150 
151  virtual int getDefaultDelay() const = 0;
152 
153  virtual int getDefaultPort() const = 0;
154 
155  private:
156  void connect(LOG4CXX_NS::helpers::Pool& p);
167  void monitor();
168  bool is_closed();
171 
172 }; // class SocketAppenderSkeleton
173 } // namespace net
174 } // namespace log4cxx
175 
176 #endif // _LOG4CXX_NET_SOCKET_APPENDER_SKELETON_H
177 
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:69
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
Activate the options that were previously set with calls to option setters.
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
std::basic_string< logchar > LogString
Definition: logstring.h:60