12 #ifdef LOG4CPP_HAVE_UNISTD_H 18 #include <sys/types.h> 29 #include <sys/socket.h> 30 #include <netinet/in.h> 31 #include <arpa/inet.h> 47 }
else if (priority > 7) {
50 result = priorities[priority];
58 const std::string& syslogName,
59 const std::string& relayer,
86 struct hostent *pent = gethostbyname (
_relayer.c_str ());
89 if (WSAGetLastError () == WSANOTINITIALISED) {
93 err = WSAStartup (0x101, &wsaData );
98 pent = gethostbyname (
_relayer.c_str ());
108 pent = gethostbyaddr ((
const char *) &ip,
sizeof(
in_addr_t), AF_INET);
118 if ((
_socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
136 const std::string message(
_getLayout().format(event));
137 size_t messageLength = message.length();
138 char *buf =
new char [messageLength + 16];
140 int preambleLength = sprintf (buf,
"<%d>", priority);
141 memcpy (buf + preambleLength, message.data(), messageLength);
144 sain.sin_family = AF_INET;
147 sain.sin_addr.s_addr =
_ipAddr;
149 while (messageLength > 0) {
152 if (preambleLength + messageLength > 900) {
153 sendto (
_socket, buf, 900, 0, (
struct sockaddr *) &sain,
sizeof (sain));
154 messageLength -= (900 - preambleLength);
155 std::memmove (buf + preambleLength, buf + 900, messageLength);
158 sendto (
_socket, buf, preambleLength + messageLength, 0, (
struct sockaddr *) &sain,
sizeof (sain));
174 std::string name, syslog_name, relayer;
175 int facility = -1, port_number = -1;
176 params.
get_for(
"remote syslog appender").
required(
"name", name)(
"syslog_name", syslog_name)(
"relayer", relayer)
177 .
optional(
"facility", facility)(
"port", port_number);
178 return std::auto_ptr<Appender>(
new RemoteSyslogAppender(name, syslog_name, relayer, facility, port_number));
const std::string _relayer
normal but significant condition
std::auto_ptr< Appender > create_remote_syslog_appender(const FactoryParams &)
virtual void _append(const LoggingEvent &event)
action must be taken immediately
required_params_validator required(const char *param, T &value) const
RemoteSyslogAppender(const std::string &name, const std::string &syslogName, const std::string &relayer, int facility=LOG_USER, int portNumber=514)
virtual ~RemoteSyslogAppender()
const std::string _syslogName
details::parameter_validator get_for(const char *tag) const
static int toSyslogPriority(Priority::Value priority)
optional_params_validator optional(const char *param, T &value) const
random user-level messages