Hi everyone,
Again, I'm just trying stuff out to try and learn a bit more but here goes...
I created a small Logger util - I included the pthread library and added a mutex lock in each of the "write*" functions, tested it by running a few instances of a test program, each printing "hello world" 100,000 times to the same file the it seems to work - no lines were cut off or anything, and each instance seemed to wait it's turn... thing is, is it really this easy to make a thread safe logger?
How I plan on using it was say in the main () of my program, create a logger like
Log* myLogger = new Log ();
Then for each object/whatnot that needs logging, pass that pointer into it so it's all logging to the same place and so on.
Also, I'm sure someone has asked this a thousand times so sorry in advance! but how would you go about making the logger work like the stringstream class i.e.
myLogger->writeInfo () << "Log messages " << count << " Times";
Any help or comments would be much appreciated :)