log4cplus::SocketAppender Class Reference

Sends `spi::InternalLoggingEvent` objects to a remote a log server. More...

`#include <socketappender.h>`

Inheritance diagram for log4cplus::SocketAppender:
[legend]
Collaboration diagram for log4cplus::SocketAppender:
[legend]

## Public Member Functions

| SocketAppender (const log4cplus::tstring &host, unsigned short port, const log4cplus::tstring &serverName=tstring(), bool ipv6=false)
| SocketAppender (const log4cplus::helpers::Properties &properties)
| ~SocketAppender ()
virtual void | close ()
| Release any resources allocated within the appender such as file handles, network connections, etc.
Public Member Functions inherited from log4cplus::Appender
| Appender ()
| Appender (const log4cplus::helpers::Properties &properties)
virtual | ~Appender ()
void | destructorImpl ()
| This function is for derived appenders to call from their destructors.
bool | isClosed () const
| Check if this appender is in closed state.
void | syncDoAppend (const log4cplus::spi::InternalLoggingEvent &event)
| This method performs threshold checks and invokes filters before delegating actual logging to the subclasses specific `append` method.
void | asyncDoAppend (const log4cplus::spi::InternalLoggingEvent &event)
| This method performs book keeping related to asynchronous logging and executes syncDoAppend() to do the actual logging.
void | doAppend (const log4cplus::spi::InternalLoggingEvent &event)
| This function checks async flag.
virtual log4cplus::tstring | getName ()
| Get the name of this appender.
virtual void | setName (const log4cplus::tstring &name)
| Set the name of this appender.
virtual void | setErrorHandler (std::unique_ptr< ErrorHandler > eh)
| Set the `ErrorHandler` for this Appender.
virtual ErrorHandler * | getErrorHandler ()
| Return the currently set `ErrorHandler` for this Appender.
virtual void | setLayout (std::unique_ptr< Layout > layout)
| Set the layout for this appender.
virtual Layout * | getLayout ()
| Returns the layout of this appender.
void | setFilter (log4cplus::spi::FilterPtr f)
| Set the filter chain on this Appender.
log4cplus::spi::FilterPtr | getFilter () const
| Get the filter chain on this Appender.
void | addFilter (log4cplus::spi::FilterPtr f)
| Add filter at the end of the filters chain.
void | addFilter (std::function< spi::FilterResult(const log4cplus::spi::InternalLoggingEvent &)>)
| Add filter at the end of the filters chain.
LogLevel | getThreshold () const
| Returns this appenders threshold LogLevel.
void | setThreshold (LogLevel th)
| Set the threshold LogLevel.
bool | isAsSevereAsThreshold (LogLevel ll) const
| Check whether the message LogLevel is below the appender's threshold.
void | waitToFinishAsyncLogging ()
| This method waits for all events that are being asynchronously logged to finish.
Public Member Functions inherited from log4cplus::helpers::SharedObject
void | addReference () const LOG4CPLUS_NOEXCEPT
void | removeReference () const

## Protected Member Functions

void | openSocket ()
void | initConnector ()
virtual void | append (const spi::InternalLoggingEvent &event)
| Subclasses of `Appender` should implement this method to perform actual logging.
virtual thread::Mutex const & | ctcGetAccessMutex () const
virtual helpers::Socket & | ctcGetSocket ()
virtual helpers::Socket | ctcConnect ()
virtual void | ctcSetConnected ()
| Sets connected flag to true in ConnectorThread's client.
Protected Member Functions inherited from log4cplus::Appender
tstring & | formatEvent (const log4cplus::spi::InternalLoggingEvent &event) const
Protected Member Functions inherited from log4cplus::helpers::SharedObject
| SharedObject ()
| SharedObject (const SharedObject &)
| SharedObject (SharedObject &&)
virtual | ~SharedObject ()
SharedObject & | operator= (const SharedObject &) LOG4CPLUS_NOEXCEPT
SharedObject & | operator= (SharedObject &&) LOG4CPLUS_NOEXCEPT
Protected Member Functions inherited from log4cplus::helpers::IConnectorThreadClient
virtual | ~IConnectorThreadClient ()

## Protected Attributes

log4cplus::helpers::Socket | socket
log4cplus::tstring | host
unsigned int | port
log4cplus::tstring | serverName
bool | ipv6 = false
volatile bool | connected
helpers::SharedObjectPtr< helpers::ConnectorThread > | connector
Protected Attributes inherited from log4cplus::Appender
std::unique_ptr< Layout > | layout
| The layout variable does not need to be set if the appender implementation has its own layout.
log4cplus::tstring | name
| Appenders are named.
LogLevel | threshold
| There is no LogLevel threshold filtering by default.
log4cplus::spi::FilterPtr | filter
| The first filter in the filter chain.
std::unique_ptr< ErrorHandler > | errorHandler
| It is assumed and enforced that errorHandler is never null.
std::unique_ptr< helpers::LockFile > | lockFile
| Optional system wide synchronization lock.
bool | useLockFile
bool | async
| Asynchronous append.
std::atomic< std::size_t > | in_flight
std::mutex | in_flight_mutex
std::condition_variable | in_flight_condition
bool | closed
| Is this appender closed?

## Additional Inherited Members

Public Attributes inherited from log4cplus::helpers::SharedObject
thread::Mutex | access_mutex

## Detailed Description

Sends `spi::InternalLoggingEvent` objects to a remote a log server.

The SocketAppender has the following properties:

- Remote logging is non-intrusive as far as the log event is concerned. In other words, the event will be logged with the same time stamp, NDC, location info as if it were logged locally by the client.

- SocketAppenders do not use a layout.

- Remote logging uses the TCP protocol. Consequently, if the server is reachable, then log events will eventually arrive at the server.

- If the remote server is down, the logging requests are simply dropped. However, if and when the server comes back up, then event transmission is resumed transparently. This transparent reconneciton is performed by a connector thread which periodically attempts to connect to the server.

- Logging events are automatically buffered by the native TCP implementation. This means that if the link to server is slow but still faster than the rate of (log) event production by the client, the client will not be affected by the slow network connection. However, if the network connection is slower then the rate of event production, then the client can only progress at the network rate. In particular, if the network link to the the server is down, the client will be blocked.

- On the other hand, if the network link is up, but the server is down, the client will not be blocked when making log requests but the log events will be lost due to server unavailability.

### Properties

host

  Remote host name to connect and send events to.

port

  Port on remote host to send events to.

ServerName

  Host name of event's origin prepended to each event.

IPv6

  Boolean value specifying whether to use IPv6 (true) or IPv4 (false). Default value is false.

Definition at line 105 of file socketappender.h.

## Constructor & Destructor Documentation

## SocketAppender() [1/2]

log4cplus::SocketAppender::SocketAppender | ( | const log4cplus::tstring & | host,
|  | unsigned short | port,
|  | const log4cplus::tstring & | serverName = tstring(),
|  | bool | ipv6 = false )

References host, ipv6, port, and serverName.

## SocketAppender() [2/2]

log4cplus::SocketAppender::SocketAppender | ( | const log4cplus::helpers::Properties & | properties | ) |

## ~SocketAppender()

log4cplus::SocketAppender::~SocketAppender | ( |  | ) |

## Member Function Documentation

## append()

virtual void log4cplus::SocketAppender::append | ( | const spi::InternalLoggingEvent & | event | ) |

protected virtual

Subclasses of `Appender` should implement this method to perform actual logging.

See also
  doAppend method.

Implements log4cplus::Appender.

## close()

virtual void log4cplus::SocketAppender::close | ( |  | ) |

virtual

Release any resources allocated within the appender such as file handles, network connections, etc.

It is a programming error to append to a closed appender.

Implements log4cplus::Appender.

## ctcConnect()

virtual helpers::Socket log4cplus::SocketAppender::ctcConnect | ( |  | ) |

protected virtual

Returns
  ConnectorThread client's function returning connected socket.

Implements log4cplus::helpers::IConnectorThreadClient.

## ctcGetAccessMutex()

virtual thread::Mutex const & log4cplus::SocketAppender::ctcGetAccessMutex | ( |  | ) | const

protected virtual

Returns
  Mutex for synchronization between ConnectorThread and its client object. This is usually SharedObject::access_mutex.

Implements log4cplus::helpers::IConnectorThreadClient.

## ctcGetSocket()

virtual helpers::Socket & log4cplus::SocketAppender::ctcGetSocket | ( |  | ) |

protected virtual

Returns
  Socket variable in ConnectorThread client to maintain.

Implements log4cplus::helpers::IConnectorThreadClient.

## ctcSetConnected()

virtual void log4cplus::SocketAppender::ctcSetConnected | ( |  | ) |

protected virtual

Sets connected flag to true in ConnectorThread's client.

Implements log4cplus::helpers::IConnectorThreadClient.

## initConnector()

void log4cplus::SocketAppender::initConnector | ( |  | ) |

protected

## openSocket()

void log4cplus::SocketAppender::openSocket | ( |  | ) |

protected

## Member Data Documentation

## connected

volatile bool log4cplus::SocketAppender::connected

protected

Definition at line 142 of file socketappender.h.

## connector

helpers::SharedObjectPtr<helpers::ConnectorThread> log4cplus::SocketAppender::connector

protected

Definition at line 143 of file socketappender.h.

## host

log4cplus::tstring log4cplus::SocketAppender::host

protected

Definition at line 131 of file socketappender.h.

Referenced by SocketAppender().

## ipv6

bool log4cplus::SocketAppender::ipv6 = false

protected

Definition at line 134 of file socketappender.h.

Referenced by SocketAppender().

## port

unsigned int log4cplus::SocketAppender::port

protected

Definition at line 132 of file socketappender.h.

Referenced by SocketAppender().

## serverName

log4cplus::tstring log4cplus::SocketAppender::serverName

protected

Definition at line 133 of file socketappender.h.

Referenced by SocketAppender().

## socket

log4cplus::helpers::Socket log4cplus::SocketAppender::socket

protected

Definition at line 130 of file socketappender.h.

The documentation for this class was generated from the following file:

- socketappender.h