Update of /cvsroot/objecthandler/log4cxx-0.9.7/include/log4cxx/net
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25784/include/log4cxx/net
Added Files:
Makefile.am smtpappender.h socketappender.h
sockethubappender.h socketnode.h syslogappender.h
telnetappender.h xmlsocketappender.h
Log Message:
--- NEW FILE: telnetappender.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* 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 _LOG4CXX_NET_TELNET_APPENDER_H
#define _LOG4CXX_NET_TELNET_APPENDER_H
#include <log4cxx/appenderskeleton.h>
#include <log4cxx/helpers/socket.h>
#include <log4cxx/helpers/serversocket.h>
#include <log4cxx/helpers/thread.h>
#include <vector>
namespace log4cxx
{
namespace helpers
{
class SocketOutputStream;
typedef helpers::ObjectPtrT<SocketOutputStream> SocketOutputStreamPtr;
}
namespace net
{
/**
<p>The TelnetAppender is a log4cxx appender that specializes in
writing to a read-only socket. The output is provided in a
telnet-friendly way so that a log can be monitored over TCP/IP.
Clients using telnet connect to the socket and receive log data.
This is handy for remote monitoring, especially when monitoring a
servlet.
<p>Here is a list of the available configuration options:
<table border=1>
<tr>
<td align=center><b>Name</b></td>
<td align=center><b>Requirement</b></td>
<td align=center><b>Description</b></td>
<td align=center><b>Sample Value</b></td>
</tr>
<tr>
<td>Port</td>
<td>optional</td>
<td>This parameter determines the port to use for announcing log events. The default port is 23 (telnet).</td>
<td>5875</td>
</table>
*/
class LOG4CXX_EXPORT TelnetAppender : public AppenderSkeleton
{
class SocketHandler;
friend class SocketHandler;
private:
static int DEFAULT_PORT;
SocketHandler * sh;
int port;
public:
DECLARE_LOG4CXX_OBJECT(TelnetAppender)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(TelnetAppender)
LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
END_LOG4CXX_CAST_MAP()
TelnetAppender();
~TelnetAppender();
/**
This appender requires a layout to format the text to the
attached client(s). */
virtual bool requiresLayout() const
{ return true; }
/** all of the options have been set, create the socket handler and
wait for connections. */
void activateOptions();
/**
Set options
*/
virtual void setOption(const String& option, const String& value);
/**
Returns value of the <b>Port</b> option.
*/
int getPort() const
{ return port; }
/**
The <b>Port</b> option takes a positive integer representing
the port where the server is waiting for connections.
*/
void setPort(int port)
{ this->port = port; }
/** shuts down the appender. */
void close();
protected:
/** Handles a log event. For this appender, that means writing the
message to each connected client. */
virtual void append(const spi::LoggingEventPtr& event) ;
//---------------------------------------------------------- SocketHandler:
private:
/** The SocketHandler class is used to accept connections from
clients. It is threaded so that clients can connect/disconnect
asynchronously. */
class LOG4CXX_EXPORT SocketHandler : public helpers::Thread
{
private:
bool done;
std::vector<helpers::SocketOutputStreamPtr> writers;
std::vector<helpers::SocketPtr> connections;
helpers::ServerSocket serverSocket;
std::vector<helpers::SocketPtr>::size_type MAX_CONNECTIONS;
public:
SocketHandler(int port);
/** make sure we close all network connections when this handler
is destroyed. */
void finalize();
/** sends a message to each of the clients in telnet-friendly output. */
void send(const String& message);
/**
Continually accepts client connections. Client connections
are refused when MAX_CONNECTIONS is reached.
*/
virtual void run();
protected:
void print(helpers::SocketOutputStreamPtr& os, const String& sz);
}; // class SocketHandler
}; // class TelnetAppender
} // namespace net
}; // namespace log4cxx
#endif // _LOG4CXX_NET_TELNET_APPENDER_H
--- NEW FILE: socketappender.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* 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 _LOG4CXX_NET_SOCKET_APPENDER_H
#define _LOG4CXX_NET_SOCKET_APPENDER_H
#include <log4cxx/appenderskeleton.h>
#include <log4cxx/helpers/socket.h>
#include <log4cxx/helpers/thread.h>
namespace log4cxx
{
namespace helpers
{
class SocketOutputStream;
typedef helpers::ObjectPtrT<SocketOutputStream> SocketOutputStreamPtr;
}
namespace net
{
class LOG4CXX_EXPORT SocketAppender;
typedef helpers::ObjectPtrT<SocketAppender> SocketAppenderPtr;
/**
Sends {@link spi::LoggingEvent LoggingEvent} objects to a remote a log server,
usually a {@link net::SocketNode SocketNode}.
<p>The SocketAppender has the following properties:
- If sent to a {@link net::SocketNode SocketNode}, 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, {@link
NDC NDC}, location info as if it were logged locally by
the client.
- SocketAppenders do not use a layout. They ship a
serialized {@link spi::LoggingEvent LoggingEvent} object
to the server side.
- 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 <em>connector</em>
thread which periodically attempts to connect to the server.
- Logging events are automatically <em>buffered</em> 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.
@n @n 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.
- Even if a <code>SocketAppender</code> is no longer
attached to any logger, it will not be destroyed in
the presence of a connector thread. A connector thread exists
only if the connection to the server is down. To avoid this
destruction problem, you should #close the the
<code>SocketAppender</code> explicitly. See also next item.
@n @n Long lived applications which create/destroy many
<code>SocketAppender</code> instances should be aware of this
destruction problem. Most other applications can safely
ignore it.
- If the application hosting the <code>SocketAppender</code>
exits before the <code>SocketAppender</code> is closed either
explicitly or subsequent to destruction, then there might
be untransmitted data in the pipe which might be lost.
@n @n To avoid lost data, it is usually sufficient to
#close the <code>SocketAppender</code> either explicitly or by
calling the LogManager#shutdown method
before exiting the application.
*/
class LOG4CXX_EXPORT SocketAppender : public AppenderSkeleton
{
class Connector;
friend class Connector;
public:
/**
The default port number of remote logging server (4560).
*/
static int DEFAULT_PORT;
/**
The default reconnection delay (30000 milliseconds or 30 seconds).
*/
static int DEFAULT_RECONNECTION_DELAY;
protected:
/**
host name
*/
String remoteHost;
/**
IP address
*/
helpers::InetAddress address;
int port;
helpers::SocketOutputStreamPtr os;
int reconnectionDelay;
bool locationInfo;
public:
DECLARE_LOG4CXX_OBJECT(SocketAppender)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(SocketAppender)
LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
END_LOG4CXX_CAST_MAP()
SocketAppender();
~SocketAppender();
/**
Connects to remote server at <code>address</code> and <code>port</code>.
*/
SocketAppender(unsigned long address, int port);
/**
Connects to remote server at <code>host</code> and <code>port</code>.
*/
SocketAppender(const String& host, int port);
/**
Connect to the specified <b>RemoteHost</b> and <b>Port</b>.
*/
void activateOptions();
/**
Set options
*/
virtual void setOption(const String& option, const String& value);
/**
* Close this appender.
*
* <p>This will mark the appender as closed and call then
* #cleanUp method.
* */
void close();
/**
* Drop the connection to the remote host and release the underlying
* connector thread if it has been created
* */
void cleanUp();
void connect();
virtual void append(const spi::LoggingEventPtr& event);
/**
* The SocketAppender does not use a layout. Hence, this method
* returns <code>false</code>.
* */
bool requiresLayout() const
{ return false; }
/**
* The <b>RemoteHost</b> option takes a string value which should be
* the host name of the server where a
* {@link net::SocketNode SocketNode} is running.
* */
inline void setRemoteHost(const String& host)
{ address = helpers::InetAddress::getByName(host);
remoteHost = host; }
/**
Returns value of the <b>RemoteHost</b> option.
*/
inline const String& getRemoteHost() const
{ return remoteHost; }
/**
The <b>Port</b> option takes a positive integer representing
the port where the server is waiting for connections.
*/
void setPort(int port)
{ this->port = port; }
/**
Returns value of the <b>Port</b> option.
*/
int getPort() const
{ return port; }
/**
The <b>LocationInfo</b> option takes a boolean value. If true,
the information sent to the remote host will include location
information. By default no location information is sent to the server.
*/
void setLocationInfo(bool locationInfo)
{ this->locationInfo = locationInfo; }
/**
Returns value of the <b>LocationInfo</b> option.
*/
bool getLocationInfo() const
{ return locationInfo; }
/**
The <b>ReconnectionDelay</b> option takes a positive integer
representing the number of milliseconds to wait between each
failed connection attempt to the server. The default value of
this option is 30000 which corresponds to 30 seconds.
<p>Setting this option to zero turns off reconnection
capability.
*/
void setReconnectionDelay(int reconnectionDelay)
{ this->reconnectionDelay = reconnectionDelay; }
/**
Returns value of the <b>ReconnectionDelay</b> option.
*/
int getReconnectionDelay() const
{ return reconnectionDelay; }
void fireConnector();
private:
/**
The Connector will reconnect when the server becomes available
again. It does this by attempting to open a new connection every
<code>reconnectionDelay</code> milliseconds.
<p>It stops trying whenever a connection is established. It will
restart to try reconnect to the server when previpously open
connection is droppped.
*/
class LOG4CXX_EXPORT Connector : public helpers::Thread
{
public:
typedef helpers::Thread BASE_CLASS;
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(Connector)
LOG4CXX_CAST_ENTRY_CHAIN(BASE_CLASS)
END_LOG4CXX_CAST_MAP()
bool interrupted;
SocketAppender * socketAppender;
Connector(SocketAppender * socketAppender);
virtual void run();
}; // class Connector
typedef helpers::ObjectPtrT<Connector> ConnectorPtr;
ConnectorPtr connector;
}; // class SocketAppender
} // namespace net
}; // namespace log4cxx
#endif // _LOG4CXX_NET_SOCKET_APPENDER_H
--- NEW FILE: xmlsocketappender.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* 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 _LOG4CXX_NET_XML_SOCKET_APPENDER_H
#define _LOG4CXX_NET_XML_SOCKET_APPENDER_H
#include <log4cxx/appenderskeleton.h>
#include <log4cxx/helpers/socket.h>
#include <log4cxx/helpers/thread.h>
namespace log4cxx
{
namespace helpers
{
class SocketOutputStream;
typedef helpers::ObjectPtrT<SocketOutputStream> SocketOutputStreamPtr;
}
namespace net
{
class XMLSocketAppender;
typedef helpers::ObjectPtrT<XMLSocketAppender> XMLSocketAppenderPtr;
/**
Sends {@link spi::LoggingEvent LoggingEvent} objects in XML format
to a remote a log server, usually a XMLSocketNode.
<p>The XMLSocketAppender has the following properties:
- If sent to a XMLSocketNode, 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, {@link
NDC NDC}, location info as if it were logged locally by
the client.
- XMLSocketAppenders use exclusively an XMLLayout. They ship an
XML stream representing a {@link spi::LoggingEvent LoggingEvent} object
to the server side.
- 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 <em>connector</em>
thread which periodically attempts to connect to the server.
- Logging events are automatically <em>buffered</em> 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.
@n @n 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.
- Even if an <code>XMLSocketAppender</code> is no longer
attached to any logger, it will not be destroyed in
the presence of a connector thread. A connector thread exists
only if the connection to the server is down. To avoid this
destruction problem, you should #close the the
<code>XMLSocketAppender</code> explicitly. See also next item.
@n @n Long lived applications which create/destroy many
<code>XMLSocketAppender</code> instances should be aware of this
destruction problem. Most other applications can safely
ignore it.
- If the application hosting the <code>XMLSocketAppender</code>
exits before the <code>XMLSocketAppender</code> is closed either
explicitly or subsequent to destruction, then there might
be untransmitted data in the pipe which might be lost.
@n @n To avoid lost data, it is usually sufficient to
#close the <code>XMLSocketAppender</code> either explicitly or by
calling the LogManager#shutdown method
before exiting the application.
*/
class LOG4CXX_EXPORT XMLSocketAppender : public AppenderSkeleton
{
class Connector;
friend class Connector;
public:
/**
The default port number of remote logging server (4560).
*/
static int DEFAULT_PORT;
/**
The default reconnection delay (30000 milliseconds or 30 seconds).
*/
static int DEFAULT_RECONNECTION_DELAY;
protected:
/**
host name
*/
String remoteHost;
/**
IP address
*/
helpers::InetAddress address;
int port;
helpers::SocketOutputStreamPtr os;
int reconnectionDelay;
bool locationInfo;
char zeroBuffer[1024];
/**
An event XML stream cannot exceed 1024 bytes.
*/
static const int MAX_EVENT_LEN;
public:
DECLARE_LOG4CXX_OBJECT(XMLSocketAppender)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(XMLSocketAppender)
LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
END_LOG4CXX_CAST_MAP()
XMLSocketAppender();
~XMLSocketAppender();
/**
Connects to remote server at <code>address</code> and <code>port</code>.
*/
XMLSocketAppender(unsigned long address, int port);
/**
Connects to remote server at <code>host</code> and <code>port</code>.
*/
XMLSocketAppender(const String& host, int port);
/**
Connect to the specified <b>RemoteHost</b> and <b>Port</b>.
*/
void activateOptions();
/**
Set options
*/
virtual void setOption(const String& option, const String& value);
/**
* Close this appender.
*
* <p>This will mark the appender as closed and call then
* #cleanUp method.
* */
void close();
/**
* Drop the connection to the remote host and release the underlying
* connector thread if it has been created
* */
void cleanUp();
void connect();
virtual void append(const spi::LoggingEventPtr& event);
/**
* The XMLSocketAppender use an internal XMLLayout. Hence, this method
* returns <code>false</code>.
* */
bool requiresLayout() const
{ return false; }
/**
* The <b>RemoteHost</b> option takes a string value which should be
* the host name of the server where an
* XMLSocketNode is running.
* */
inline void setRemoteHost(const String& host)
{ address = helpers::InetAddress::getByName(host);
remoteHost = host; }
/**
Returns value of the <b>RemoteHost</b> option.
*/
inline const String& getRemoteHost() const
{ return remoteHost; }
/**
The <b>Port</b> option takes a positive integer representing
the port where the server is waiting for connections.
*/
void setPort(int port)
{ this->port = port; }
/**
Returns value of the <b>Port</b> option.
*/
int getPort() const
{ return port; }
/**
The <b>LocationInfo</b> option takes a boolean value. If true,
the information sent to the remote host will include location
information. By default no location information is sent to the server.
*/
void setLocationInfo(bool locationInfo)
{ this->locationInfo = locationInfo; }
/**
Returns value of the <b>LocationInfo</b> option.
*/
bool getLocationInfo() const
{ return locationInfo; }
/**
The <b>ReconnectionDelay</b> option takes a positive integer
representing the number of milliseconds to wait between each
failed connection attempt to the server. The default value of
this option is 30000 which corresponds to 30 seconds.
<p>Setting this option to zero turns off reconnection
capability.
*/
void setReconnectionDelay(int reconnectionDelay)
{ this->reconnectionDelay = reconnectionDelay; }
/**
Returns value of the <b>ReconnectionDelay</b> option.
*/
int getReconnectionDelay() const
{ return reconnectionDelay; }
void fireConnector();
private:
/**
The Connector will reconnect when the server becomes available
again. It does this by attempting to open a new connection every
<code>reconnectionDelay</code> milliseconds.
<p>It stops trying whenever a connection is established. It will
restart to try reconnect to the server when previpously open
connection is droppped.
*/
class LOG4CXX_EXPORT Connector : public helpers::Thread
{
public:
bool interrupted;
XMLSocketAppender * socketAppender;
Connector(XMLSocketAppenderPtr socketAppender);
virtual void run();
}; // class Connector
Connector * connector;
}; // class XMLSocketAppender
} // namespace net
}; // namespace log4cxx
#endif // _LOG4CXX_NET_XML_SOCKET_APPENDER_H
--- NEW FILE: sockethubappender.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* 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 _LOG4CXX_NET_SOCKET_HUB_APPENDER_H
#define _LOG4CXX_NET_SOCKET_HUB_APPENDER_H
#include <log4cxx/appenderskeleton.h>
#include <log4cxx/helpers/socket.h>
#include <log4cxx/helpers/thread.h>
#include <vector>
#include <log4cxx/helpers/socket.h>
namespace log4cxx
{
namespace helpers
{
class SocketOutputStream;
typedef helpers::ObjectPtrT<SocketOutputStream> SocketOutputStreamPtr;
}
namespace net
{
/**
Sends {@link spi::LoggingEvent LoggingEvent} objects to a set of remote log
servers, usually a SocketNode.
<p>Acts just like SocketAppender except that instead of
connecting to a given remote log server,
<code>SocketHubAppender</code> accepts connections from the remote
log servers as clients. It can accept more than one connection.
When a log event is received, the event is sent to the set of
currently connected remote log servers. Implemented this way it does
not require any update to the configuration file to send data to
another remote log server. The remote log server simply connects to
the host and port the <code>SocketHubAppender</code> is running on.
<p>The <code>SocketHubAppender</code> does not store events such
that the remote side will events that arrived after the
establishment of its connection. Once connected, events arrive in
order as guaranteed by the TCP protocol.
<p>This implementation borrows heavily from the SocketAppender.
<p>The SocketHubAppender has the following characteristics:
- If sent to a SocketNode, 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.
- <code>SocketHubAppender</code> does not use a layout. It
ships a serialized spi::LoggingEvent object to the remote side.
- <code>SocketHubAppender</code> relies on the TCP
protocol. Consequently, if the remote side is reachable, then log
events will eventually arrive at remote client.
- If no remote clients are attached, the logging requests are
simply dropped.
- Logging events are automatically <em>buffered</em> by the
native TCP implementation. This means that if the link to remote
client is slow but still faster than the rate of (log) event
production, the application will not be affected by the slow network
connection. However, if the network connection is slower then the
rate of event production, then the local application can only
progress at the network rate. In particular, if the network link to
the the remote client is down, the application will be blocked.
@n @n On the other hand, if the network link is up, but the remote
client is down, the client will not be blocked when making log
requests but the log events will be lost due to client
unavailability.
@n @n The single remote client case extends to multiple clients
connections. The rate of logging will be determined by the slowest
link.
- If the application hosting the <code>SocketHubAppender</code>
exits before the <code>SocketHubAppender</code> is closed either
explicitly or subsequent to garbage collection, then there might
be untransmitted data in the pipe which might be lost. This is a
common problem on Windows based systems.
@n @n To avoid lost data, it is usually sufficient to #close
the <code>SocketHubAppender</code> either explicitly or by calling
the LogManager#shutdown method before
exiting the application.
*/
class LOG4CXX_EXPORT SocketHubAppender : public AppenderSkeleton
{
private:
/**
The default port number of the ServerSocket will be created on.
*/
static int DEFAULT_PORT;
int port;
std::vector<helpers::SocketOutputStreamPtr> oosList;
bool locationInfo;
public:
DECLARE_LOG4CXX_OBJECT(SocketHubAppender)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(SocketHubAppender)
LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
END_LOG4CXX_CAST_MAP()
SocketHubAppender();
~SocketHubAppender();
/**
Connects to remote server at <code>address</code> and <code>port</code>.
*/
SocketHubAppender(int port) ;
/**
Set up the socket server on the specified port.
*/
virtual void activateOptions();
/**
Set options
*/
virtual void setOption(const String& option, const String& value);
/**
Close this appender.
<p>This will mark the appender as closed and
call then #cleanUp method.
*/
virtual void close();
/**
Release the underlying ServerMonitor thread, and drop the connections
to all connected remote servers. */
void cleanUp();
/**
Append an event to all of current connections. */
virtual void append(const spi::LoggingEventPtr& event);
/**
The SocketHubAppender does not use a layout. Hence, this method returns
<code>false</code>. */
virtual bool requiresLayout() const
{ return false; }
/**
The <b>Port</b> option takes a positive integer representing
the port where the server is waiting for connections. */
inline void setPort(int port)
{ this->port = port; }
/**
Returns value of the <b>Port</b> option. */
inline int getPort() const
{ return port; }
/**
The <b>LocationInfo</b> option takes a boolean value. If true,
the information sent to the remote host will include location
information. By default no location information is sent to the server. */
inline void setLocationInfo(bool locationInfo)
{ this->locationInfo = locationInfo; }
/**
Returns value of the <b>LocationInfo</b> option. */
inline bool getLocationInfo() const
{ return locationInfo; }
/**
Start the ServerMonitor thread. */
private:
void startServer();
/**
This class is used internally to monitor a ServerSocket
and register new connections in a vector passed in the
constructor. */
class LOG4CXX_EXPORT ServerMonitor :
public helpers::Runnable,
public helpers::ObjectImpl
{
private:
int port;
std::vector<helpers::SocketOutputStreamPtr> oosList;
bool keepRunning;
helpers::Thread * monitorThread;
public:
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(ServerMonitor)
END_LOG4CXX_CAST_MAP()
/**
Create a thread and start the monitor. */
ServerMonitor(int port,
const std::vector<helpers::SocketOutputStreamPtr>& oosList);
/**
Stops the monitor. This method will not return until
the thread has finished executing. */
void stopMonitor();
/**
Method that runs, monitoring the ServerSocket and adding connections as
they connect to the socket. */
void run();
}; // class ServerMonitor
typedef helpers::ObjectPtrT<ServerMonitor> ServerMonitorPtr;
ServerMonitorPtr serverMonitor;
}; // class SocketHubAppender
} // namespace net
}; // namespace log4cxx
#endif // _LOG4CXX_NET_SOCKET_HUB_APPENDER_H
--- NEW FILE: Makefile.am ---
netincdir = $(includedir)/log4cxx/net
netinc_HEADERS= $(top_srcdir)/include/log4cxx/net/*.h
--- NEW FILE: syslogappender.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* 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 _LOG4CXX_NET_SYSLOG_APPENDER_H
#define _LOG4CXX_NET_SYSLOG_APPENDER_H
#include <log4cxx/appenderskeleton.h>
#include <log4cxx/helpers/syslogwriter.h>
#ifndef HAVE_SYSLOG
#endif
namespace log4cxx
{
namespace net
{
class SyslogAppender;
typedef helpers::ObjectPtrT<SyslogAppender> SyslogAppenderPtr;
/** Use SyslogAppender to send log messages to a remote syslog daemon.*/
class LOG4CXX_EXPORT SyslogAppender : public AppenderSkeleton
{
public:
DECLARE_LOG4CXX_OBJECT(SyslogAppender)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(SyslogAppender)
LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
END_LOG4CXX_CAST_MAP()
SyslogAppender();
SyslogAppender(const LayoutPtr& layout, int syslogFacility);
SyslogAppender(const LayoutPtr& layout,
const String& syslogHost, int syslogFacility);
~SyslogAppender();
/** Release any resources held by this SyslogAppender.*/
void close();
/**
Returns the specified syslog facility as a lower-case String,
e.g. "kern", "user", etc.
*/
static String getFacilityString(int syslogFacility);
/**
Returns the integer value corresponding to the named syslog
facility, or -1 if it couldn't be recognized.
@param facilityName one of the strings KERN, USER, MAIL, DAEMON,
AUTH, SYSLOG, LPR, NEWS, UUCP, CRON, AUTHPRIV, FTP, LOCAL0,
LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7.
The matching is case-insensitive.
*/
static int getFacility(const String &facilityName);
void append(const spi::LoggingEventPtr& event);
/**
This method returns immediately as options are activated when they
are set.
*/
void activateOptions();
void setOption(const String& option, const String& value);
/**
The SyslogAppender requires a layout. Hence, this method returns
<code>true</code>.
*/
virtual bool requiresLayout() const
{ return true; }
/**
The <b>SyslogHost</b> option is the name of the the syslog host
where log output should go.
<b>WARNING</b> If the SyslogHost is not set, then this appender
will fail.
*/
void setSyslogHost(const String& syslogHost);
/**
Returns the value of the <b>SyslogHost</b> option.
*/
inline const String& getSyslogHost() const
{ return syslogHost; }
/**
Set the syslog facility. This is the <b>Facility</b> option.
<p>The <code>facilityName</code> parameter must be one of the
strings KERN, USER, MAIL, DAEMON, AUTH, SYSLOG, LPR, NEWS, UUCP,
CRON, AUTHPRIV, FTP, LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4,
LOCAL5, LOCAL6, LOCAL7. Case is unimportant.
*/
void setFacility(const String& facilityName);
/**
Returns the value of the <b>Facility</b> option.
*/
inline String getFacility() const
{ return getFacilityString(syslogFacility); }
/**
If the <b>FacilityPrinting</b> option is set to true, the printed
message will include the facility name of the application. It is
<em>false</em> by default.
*/
inline void setFacilityPrinting(bool facilityPrinting)
{ this->facilityPrinting = facilityPrinting; }
/**
Returns the value of the <b>FacilityPrinting</b> option.
*/
inline bool getFacilityPrinting() const
{ return facilityPrinting; }
protected:
void initSyslogFacilityStr();
int syslogFacility; // Have LOG_USER as default
String facilityStr;
bool facilityPrinting;
helpers::SyslogWriter * sw;
String syslogHost;
}; // class SyslogAppender
} // namespace net
}; // namespace log4cxx
#endif // _LOG4CXX_NET_SYSLOG_APPENDER_H
--- NEW FILE: socketnode.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* 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 _LOG4CXX_NET_SOCKET_NODE_H
#define _LOG4CXX_NET_SOCKET_NODE_H
#include <log4cxx/helpers/thread.h>
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/helpers/objectimpl.h>
namespace log4cxx
{
namespace helpers
{
class Socket;
typedef ObjectPtrT<Socket> SocketPtr;
class SocketInputStream;
typedef ObjectPtrT<SocketInputStream> SocketInputStreamPtr;
}
namespace spi
{
class LoggerRepository;
typedef helpers::ObjectPtrT<LoggerRepository> LoggerRepositoryPtr;
}
namespace net
{
class SocketNode;
typedef helpers::ObjectPtrT<SocketNode> SocketNodePtr;
/**
Read {@link spi::LoggingEvent LoggingEvent} objects sent from a remote
client using Sockets (TCP). These logging events are logged according
to local policy, as if they were generated locally.
<p>For example, the socket node might decide to log events to a
local file and also resent them to a second socket node.
*/
class LOG4CXX_EXPORT SocketNode :
public virtual helpers::Runnable,
public virtual helpers::ObjectImpl
{
protected:
helpers::SocketInputStreamPtr is;
spi::LoggerRepositoryPtr hierarchy;
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(SocketNode)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(SocketNode)
LOG4CXX_CAST_ENTRY(helpers::Runnable)
END_LOG4CXX_CAST_MAP()
SocketNode(helpers::SocketPtr& socket,
spi::LoggerRepositoryPtr& hierarchy);
virtual void run();
};
} // namespace net
}; // namespace log4cxx
#endif // _LOG4CXX_NET_SOCKET_NODE_H
--- NEW FILE: smtpappender.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* 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 _LOG4CXX_NET_SMTP_H
#define _LOG4CXX_NET_SMTP_H
#include <log4cxx/config.h>
#ifdef HAVE_SMTP
#include <log4cxx/appenderskeleton.h>
#include <log4cxx/helpers/cyclicbuffer.h>
#include <log4cxx/spi/triggeringeventevaluator.h>
namespace log4cxx
{
namespace net
{
class SMTPAppender;
typedef helpers::ObjectPtrT<SMTPAppender> SMTPAppenderPtr;
/**
Send an e-mail when a specific logging event occurs, typically on
errors or fatal errors.
<p>The number of logging events delivered in this e-mail depend on
the value of <b>BufferSize</b> option. The
<code>SMTPAppender</code> keeps only the last
<code>BufferSize</code> logging events in its cyclic buffer. This
keeps memory requirements at a reasonable level while still
delivering useful application context.
*/
class LOG4CXX_EXPORT SMTPAppender : public AppenderSkeleton
{
private:
String to;
String from;
String subject;
String smtpHost;
int bufferSize; // 512
bool locationInfo;
helpers::CyclicBuffer cb;
void * session;
String encoding;
String charset;
protected:
spi::TriggeringEventEvaluatorPtr evaluator;
public:
DECLARE_LOG4CXX_OBJECT(SMTPAppender)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(SMTPAppender)
LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
END_LOG4CXX_CAST_MAP()
/**
The default constructor will instantiate the appender with a
spi::TriggeringEventEvaluator that will trigger on events with
level ERROR or higher.*/
SMTPAppender();
/**
Use <code>evaluator</code> passed as parameter as the
spi::TriggeringEventEvaluator for this net::SMTPAppender.
*/
SMTPAppender(spi::TriggeringEventEvaluatorPtr evaluator);
~SMTPAppender();
/**
Set options
*/
virtual void setOption(const String& option, const String& value);
/**
Activate the specified options, such as the smtp host, the
recipient, from, etc.
*/
virtual void activateOptions();
/**
Perform SMTPAppender specific appending actions, mainly adding
the event to a cyclic buffer and checking if the event triggers
an e-mail to be sent. */
virtual void append(const spi::LoggingEventPtr& event);
/**
This method determines if there is a sense in attempting to append.
<p>It checks whether there is a set output target and also if
there is a set layout. If these checks fail, then the boolean
value <code>false</code> is returned. */
bool checkEntryConditions();
virtual void close();
std::vector<String> parseAddress(const String& addressStr);
/**
Returns value of the <b>To</b> option.
*/
inline const String& getTo() const
{ return to; }
/**
The <code>SMTPAppender</code> requires a {@link
Layout layout}. */
virtual bool requiresLayout() const
{ return true; }
/**
Send the contents of the cyclic buffer as an e-mail message.
*/
void sendBuffer();
/**
Returns value of the <b>Charset</b> option.
*/
inline const String& getCharset() const
{ return charset; }
/**
Returns value of the <b>Encoding</b> option.
*/
inline const String& getEncoding() const
{ return encoding; }
/**
Returns value of the <b>EvaluatorClass</b> option.
*/
String getEvaluatorClass();
/**
Returns value of the <b>From</b> option.
*/
inline const String& getFrom() const
{ return from; }
/**
Returns value of the <b>Subject</b> option.
*/
inline const String& getSubject() const
{ return subject; }
/**
The <b>Charset</b> option takes a string value which should be the
charset of the mail (<code>us-ascii</code>, <code>iso8859_1</code>,
<code>iso8859_2</code>, <code>iso8859_3</code>).
*/
inline void setCharset(const String& charset)
{ this->charset = charset; }
/**
The <b>Encoding</b> option takes a string value which should be the
encoding type of the mail (<code>7bit</code>, <code>8bit</code>,
<code>base64</code>, <code>binary</code>, <code>quoted</code>).
*/
inline void setEncoding(const String& charset)
{ this->encoding = encoding; }
/**
The <b>From</b> option takes a string value which should be a
e-mail address of the sender.
*/
inline void setFrom(const String& from)
{ this->from = from; }
/**
The <b>Subject</b> option takes a string value which should be a
the subject of the e-mail message.
*/
inline void setSubject(const String& subject)
{ this->subject = subject; }
/**
The <b>BufferSize</b> option takes a positive integer
representing the maximum number of logging events to collect in a
cyclic buffer. When the <code>BufferSize</code> is reached,
oldest events are deleted as new events are added to the
buffer. By default the size of the cyclic buffer is 512 events.
*/
void setBufferSize(int bufferSize);
/**
The <b>SMTPHost</b> option takes a string value which should be a
the host name of the SMTP server that will send the e-mail message.
*/
inline void setSMTPHost(const String& smtpHost)
{ this->smtpHost = smtpHost; }
/**
Returns value of the <b>SMTPHost</b> option.
*/
inline const String& getSMTPHost() const
{ return smtpHost; }
/**
The <b>To</b> option takes a string value which should be a
comma separated list of e-mail address of the recipients.
*/
inline void setTo(const String& to)
{ this->to = to; }
/**
Returns value of the <b>BufferSize</b> option.
*/
inline int getBufferSize() const
{ return bufferSize; }
/**
The <b>EvaluatorClass</b> option takes a string value
representing the name of the class implementing the
spi::TriggeringEventEvaluator interface. A corresponding object will
be instantiated and assigned as the triggering event evaluator
for the SMTPAppender.
*/
void setEvaluatorClass(const String& value);
/**
The <b>LocationInfo</b> option takes a boolean value. By
default, it is set to false which means there will be no effort
to extract the location information related to the event. As a
result, the layout that formats the events as they are sent out
in an e-mail is likely to place the wrong location information
(if present in the format).
<p>Location information extraction is comparatively very slow and
should be avoided unless performance is not a concern.
*/
inline void setLocationInfo(bool locationInfo)
{ this->locationInfo = locationInfo; }
/**
Returns value of the <b>LocationInfo</b> option.
*/
inline bool getLocationInfo() const
{ return locationInfo; }
}; // class SMTPAppender
class LOG4CXX_EXPORT DefaultEvaluator :
public virtual spi::TriggeringEventEvaluator,
public virtual helpers::ObjectImpl
{
public:
DECLARE_LOG4CXX_OBJECT(DefaultEvaluator)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(spi::TriggeringEventEvaluator)
END_LOG4CXX_CAST_MAP()
/**
Is this <code>event</code> the e-mail triggering event?
<p>This method returns <code>true</code>, if the event level
has ERROR level or higher. Otherwise it returns
<code>false</code>.
*/
virtual bool isTriggeringEvent(const spi::LoggingEventPtr& event);
}; // class DefaultEvaluator
} // namespace net
}; // namespace log4cxx
#endif // HAVE_SMTP
#endif // _LOG4CXX_NET_SMTP_H
|