xconspirisist
08-20-2010, 12:31 AM
Hey folks, I've been picking up C++ over the last couple of days and most of my experience from other languages has transferred quite well. However, I'm trying to knock up a simple logging class and it's driving me nuts. I imagine this is quite a common request, but I can only pick up bits and bobs from around the net that don't seem to fully work.
I'd just like an abstract class with a bunch of stream's, so I could effectively do this;
Logger::err << "Hello " << 1 << 2;
Logger::norm << "Goodbye " << 3 << 4;
Then, I'd like to override some sort of onWrite method, that gives me the final strings "Hello 12" and "Goodbye 34", so I can do whatever I want with the final string. I've heard people talking about overloading the << operator, but that only lets me handle each argument one at a time and I don't really want to do that.
I know it's quite a lot to ask, but could someone post a code example that would work? Again, I've found bits and bobs, but this thing is driving me nuts!
Many thanks in advance for anyone who helps out.
I'd just like an abstract class with a bunch of stream's, so I could effectively do this;
Logger::err << "Hello " << 1 << 2;
Logger::norm << "Goodbye " << 3 << 4;
Then, I'd like to override some sort of onWrite method, that gives me the final strings "Hello 12" and "Goodbye 34", so I can do whatever I want with the final string. I've heard people talking about overloading the << operator, but that only lets me handle each argument one at a time and I don't really want to do that.
I know it's quite a lot to ask, but could someone post a code example that would work? Again, I've found bits and bobs, but this thing is driving me nuts!
Many thanks in advance for anyone who helps out.