Home Projects Jobs Clientele Contact


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Log class problems

Hello, everyone

I'm trying to make a CBaseLog class, that should meet general requirements:

1) To be a stream -derived, ie iostream, ostream, etc.. and behave like a stream. I any external class can print itself to a stream - it should be able to do it with CBaseLog class.

2) Every log statement should be completed with std::endl, and for every log statement it should be a call of protected virtual method saveRow(). This method should be implemented in derived classes like CLogger (*unix logger API), CFileLog, CMemoryLog, etc..

3) CBaseLog should work identically under Windows and *nix.

I attaching my test program for your amusement..

Now, the problems:

If I'm using as a buffer a generic streambuf object, I can see that overwritten methods overflow() and xsputn(0 are called but only sometimes. Even if the size of the buffer in streambuf is set to one byte - overflow is called only once - for the very first data sent into stream..

If I'm using as a buffer a generic strstreambuf object, the overwritten methods are called more or less as expected, even that behaviour is slightly different on *nix and Windows (GCC STL vs VC++ STL). The only problem is - the allocated memory always grows with the new data sent to the stream, and I don't see how I can free the data I already used internally..

Any suggestion, code examples, etc would be gratefully accepted. RTFM is already in full use.


Authoright © Total Knowledge: 2001-2008