I want to create a logger class such that with a functionality like this:
Logger log;
log << "Error: " << value << "seen" << endl;
This should print me a custom formatted message. E.g. "12-09-2009 11:22:33 Error 5 seen"
My simple class currently looks like this:
class Logger {
private:
ostringstream oss;
public:
template <typename T>
Logger& operator<<(T a);
}
template <typename T>
Logger& Logger::operator<<(T a) {
oss << a;
return *this;
}
void functionTest(void) {
Logger log;
log << "Error: " << 5 << " seen";
}
This will cause oss to correctly have the buffer "Error: 5 seen". But I dont know what other function I need to write/modify so that something prints on the screen. Does anyone know how to get this to work or is there another way to design this class to have my functionality work?