socketappender.h
Go to the documentation of this file.
// -*- C++ -*-
// Module: LOG4CPLUS
// File: socketappender.h
// Created: 5/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2017 Tad E. Smith
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef LOG4CPLUS_SOCKET_APPENDER_HEADER_
#define LOG4CPLUS_SOCKET_APPENDER_HEADER_
#include <log4cplus/config.hxx>
#if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
#pragma once
#endif
#include <log4cplus/appender.h>
#include <log4cplus/helpers/socket.h>
#include <log4cplus/thread/syncprims.h>
#include <log4cplus/thread/threads.h>
#include <log4cplus/helpers/connectorthread.h>
namespace log4cplus
{
#ifndef UNICODE
std::size_t const LOG4CPLUS_MAX_MESSAGE_SIZE = 8*1024;
#else
std::size_t const LOG4CPLUS_MAX_MESSAGE_SIZE = 2*8*1024;
#endif
class LOG4CPLUS_EXPORT SocketAppender
: public Appender
#if ! defined (LOG4CPLUS_SINGLE_THREADED)
, protected virtual helpers::IConnectorThreadClient
#endif
{
public:
// Ctors
SocketAppender(const log4cplus::tstring& host, unsigned short port,
const log4cplus::tstring& serverName = tstring(),
bool ipv6 = false);
SocketAppender(const log4cplus::helpers::Properties & properties);
// Dtor
~SocketAppender();
// Methods
virtual void close();
protected:
void openSocket();
void initConnector ();
virtual void append(const spi::InternalLoggingEvent& event);
// Data
log4cplus::helpers::Socket socket;
log4cplus::tstring host;
unsigned int port;
log4cplus::tstring serverName;
bool ipv6 = false;
#if ! defined (LOG4CPLUS_SINGLE_THREADED)
virtual thread::Mutex const & ctcGetAccessMutex () const;
virtual helpers::Socket & ctcGetSocket ();
virtual helpers::Socket ctcConnect ();
virtual void ctcSetConnected ();
volatile bool connected;
helpers::SharedObjectPtr<helpers::ConnectorThread> connector;
#endif
private:
// Disallow copying of instances of this class
SocketAppender(const SocketAppender&);
SocketAppender& operator=(const SocketAppender&);
};
namespace helpers {
LOG4CPLUS_EXPORT
void convertToBuffer (SocketBuffer & buffer,
const log4cplus::spi::InternalLoggingEvent& event,
const log4cplus::tstring& serverName);
LOG4CPLUS_EXPORT
log4cplus::spi::InternalLoggingEvent readFromBuffer(SocketBuffer& buffer);
} // end namespace helpers
} // end namespace log4cplus
#endif // LOG4CPLUS_SOCKET_APPENDER_HEADER_
appender.h
log4cplus::Appender::Appender
Appender()
log4cplus::SocketAppender::ctcGetSocket
virtual helpers::Socket & ctcGetSocket()
log4cplus::SocketAppender::serverName
log4cplus::tstring serverName
Definition socketappender.h:133
log4cplus::SocketAppender::append
virtual void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
log4cplus::SocketAppender::port
unsigned int port
Definition socketappender.h:132
log4cplus::SocketAppender::openSocket
void openSocket()
log4cplus::SocketAppender::ctcConnect
virtual helpers::Socket ctcConnect()
log4cplus::SocketAppender::initConnector
void initConnector()
log4cplus::SocketAppender::ipv6
bool ipv6
Definition socketappender.h:134
log4cplus::SocketAppender::socket
log4cplus::helpers::Socket socket
Definition socketappender.h:130
log4cplus::SocketAppender::host
log4cplus::tstring host
Definition socketappender.h:131
log4cplus::SocketAppender::close
virtual void close()
Release any resources allocated within the appender such as file handles, network connections,...
log4cplus::SocketAppender::SocketAppender
SocketAppender(const log4cplus::tstring &host, unsigned short port, const log4cplus::tstring &serverName=tstring(), bool ipv6=false)
log4cplus::SocketAppender::~SocketAppender
~SocketAppender()
log4cplus::SocketAppender::connector
helpers::SharedObjectPtr< helpers::ConnectorThread > connector
Definition socketappender.h:143
log4cplus::SocketAppender::ctcSetConnected
virtual void ctcSetConnected()
Sets connected flag to true in ConnectorThread's client.
log4cplus::SocketAppender::SocketAppender
SocketAppender(const log4cplus::helpers::Properties &properties)
log4cplus::SocketAppender::ctcGetAccessMutex
virtual thread::Mutex const & ctcGetAccessMutex() const
log4cplus::SocketAppender::connected
volatile bool connected
Definition socketappender.h:142
log4cplus::helpers::IConnectorThreadClient
Interface implemented by users of ConnectorThread.
Definition connectorthread.h:48
log4cplus::helpers::Properties
Definition property.h:43
log4cplus::helpers::SharedObjectPtr
Definition pointer.h:101
log4cplus::helpers::SocketBuffer
Definition socketbuffer.h:43
log4cplus::helpers::Socket
This class implements client sockets (also called just "sockets").
Definition helpers/socket.h:84
log4cplus::spi::InternalLoggingEvent
The internal representation of logging events.
Definition loggingevent.h:51
log4cplus::thread::Mutex
Definition syncprims.h:83
config.hxx
connectorthread.h
socket.h
log4cplus::helpers
Definition appender.h:50
log4cplus::helpers::readFromBuffer
LOG4CPLUS_EXPORT log4cplus::spi::InternalLoggingEvent readFromBuffer(SocketBuffer &buffer)
log4cplus::helpers::convertToBuffer
LOG4CPLUS_EXPORT void convertToBuffer(SocketBuffer &buffer, const log4cplus::spi::InternalLoggingEvent &event, const log4cplus::tstring &serverName)
log4cplus
Definition appender.h:46
log4cplus::tstring
std::basic_string< tchar > tstring
Definition tstring.h:39
log4cplus::LOG4CPLUS_MAX_MESSAGE_SIZE
std::size_t const LOG4CPLUS_MAX_MESSAGE_SIZE
Definition socketappender.h:44
syncprims.h
threads.h
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition win32.h:141