Home  +  Forums  +  C++ and Sockets  +  C++ and SQL: MySQL, sqlite, ODBC  +  Miscellaneous Projects
Logo
~Sockets~
~New~
~Examples~
~Contact~

C++ Socket library tutorial

Error logging

Prev   |   Menu   |   Next

To turn on error logging, the class StdLog is used. The library contains the StdoutLog class as an example on how to use StdLog. It only has one method (error) that is called by the framework whenever something bad happens. To use a log class, it needs to be instantiated and registered with the SocketHandler. One example on how to do this is shown below. It's the displayserver that has been complemented with error logging.

The StdLog and StdoutLog classes were added in version 1.4.

server_errlog.cpp
#include <SocketHandler.h>
#include <ListenSocket.h>
#include <StdoutLog.h>

#include "DisplaySocket.h"


static	bool quit = false;

int main()
{
	SocketHandler h;
	ListenSocket<DisplaySocket> l(h);
	StdoutLog log;

	h.RegStdLog(&log);

	if (l.Bind(9001))
	{
		exit(-1);
	}
	h.Add(&l);
	h.Select(1,0);
	while (!quit)
	{
		h.Select(1,0);
	}
}



Prev   |   Menu   |   Next

Valid HTML 4.01!

Validate
Page, code, and content Copyright (C) 2021 by Anders Hedström