logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Nader" <Paul.Na...@telefonica.net>
Subject Re: Is this project still alive????
Date Fri, 19 Nov 2004 19:15:32 GMT
Hi Anton,

You need to read a LoggingEvent and then access the message, timestamp, etc
using the methods provided...

The code below implements a working client.

Regards, Paul

Consulting Engineer
RUBIX Information Technologies, Inc.
www.rubixinfotech.com

#include <iomanip>
#include <iostream>
#include <log4cxx/spi/loggingevent.h>
#include <log4cxx/helpers/socket.h>
#include <log4cxx/helpers/dateformat.h>
#include <log4cxx/helpers/inetaddress.h>

using namespace std;
using namespace log4cxx::spi;
using namespace log4cxx::helpers;

Socket *s;
extern "C" void signalHandler(int sig)
{
	if ((sig == SIGTERM) || (sig == SIGINT) || (sig == SIGPIPE))
	{
		s->close();
		exit(0);
	}
}

int main (int argc, char *argv[])
{

    if (argc != 3)
	{
		printf("SocketClient hostname port\n");
		return(1);
	}

	char *host = argv[1];
	int port = atoi(argv[2]);

	try 
	{
		InetAddress address = InetAddress::getByName(host);
		s = new Socket(address, port);
		SocketInputStreamPtr istrm = s->getInputStream();
		DateFormat dateFormat("%Y-%m-%d %H:%M:%S,%Q");
    		LoggingEvent event;
		while (true)
		{
			event.read(istrm);
			cout << dateFormat.format(event.getTimeStamp()) << " " \
			 	<< event.getLevel()->toString() << " " \
			 	<< event.getMessage() << endl;
		}
	}
	catch (SocketException &ex)
	{
		cerr << ex.getMessage() << endl;
	}
	catch (...)
	{
		cerr << "Unexpected exception" << endl;
	}

	return(0);
}


Mime
View raw message