log4cplus  2.1.0
socketappender.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Module: LOG4CPLUS
3 // File: socketappender.h
4 // Created: 5/2003
5 // Author: Tad E. Smith
6 //
7 //
8 // Copyright 2003-2017 Tad E. Smith
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 
24 #ifndef LOG4CPLUS_SOCKET_APPENDER_HEADER_
25 #define LOG4CPLUS_SOCKET_APPENDER_HEADER_
26 
27 #include <log4cplus/config.hxx>
28 
29 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
30 #pragma once
31 #endif
32 
33 #include <log4cplus/appender.h>
38 
39 
40 namespace log4cplus
41 {
42 
43 #ifndef UNICODE
44  std::size_t const LOG4CPLUS_MAX_MESSAGE_SIZE = 8*1024;
45 #else
46  std::size_t const LOG4CPLUS_MAX_MESSAGE_SIZE = 2*8*1024;
47 #endif
48 
49 
106  : public Appender
107 #if ! defined (LOG4CPLUS_SINGLE_THREADED)
108  , protected virtual helpers::IConnectorThreadClient
109 #endif
110  {
111  public:
112  // Ctors
113  SocketAppender(const log4cplus::tstring& host, unsigned short port,
114  const log4cplus::tstring& serverName = tstring(),
115  bool ipv6 = false);
117 
118  // Dtor
120 
121  // Methods
122  virtual void close();
123 
124  protected:
125  void openSocket();
126  void initConnector ();
127  virtual void append(const spi::InternalLoggingEvent& event);
128 
129  // Data
132  unsigned int port;
134  bool ipv6 = false;
135 
136 #if ! defined (LOG4CPLUS_SINGLE_THREADED)
137  virtual thread::Mutex const & ctcGetAccessMutex () const;
140  virtual void ctcSetConnected ();
141 
142  volatile bool connected;
144 #endif
145 
146  private:
147  // Disallow copying of instances of this class
149  SocketAppender& operator=(const SocketAppender&);
150  };
151 
152  namespace helpers {
156  const log4cplus::tstring& serverName);
157 
160  } // end namespace helpers
161 
162 } // end namespace log4cplus
163 
164 #endif // LOG4CPLUS_SOCKET_APPENDER_HEADER_
Extend this class for implementing your own strategies for printing log statements.
Definition: appender.h:139
Sends spi::InternalLoggingEvent objects to a remote a log server.
virtual helpers::Socket & ctcGetSocket()
log4cplus::tstring serverName
virtual void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
virtual helpers::Socket ctcConnect()
log4cplus::helpers::Socket socket
log4cplus::tstring host
virtual void close()
Release any resources allocated within the appender such as file handles, network connections,...
SocketAppender(const log4cplus::tstring &host, unsigned short port, const log4cplus::tstring &serverName=tstring(), bool ipv6=false)
helpers::SharedObjectPtr< helpers::ConnectorThread > connector
virtual void ctcSetConnected()
Sets connected flag to true in ConnectorThread's client.
SocketAppender(const log4cplus::helpers::Properties &properties)
virtual thread::Mutex const & ctcGetAccessMutex() const
Interface implemented by users of ConnectorThread.
This class implements client sockets (also called just "sockets").
The internal representation of logging events.
Definition: loggingevent.h:51
LOG4CPLUS_EXPORT log4cplus::spi::InternalLoggingEvent readFromBuffer(SocketBuffer &buffer)
LOG4CPLUS_EXPORT void convertToBuffer(SocketBuffer &buffer, const log4cplus::spi::InternalLoggingEvent &event, const log4cplus::tstring &serverName)
std::basic_string< tchar > tstring
Definition: tstring.h:39
std::size_t const LOG4CPLUS_MAX_MESSAGE_SIZE
#define LOG4CPLUS_EXPORT
Definition: win32.h:141