Original Post
Hi, I would like to write a C++ logging class for a game. Ideally at any point in my program I could write something like: global_mylog << "FramesPerSecond: " << (int)getFPS(); And in my log file write out something like: "May 29th, 2005: 11:00PM: FramesPerSecond: 60" In a word I want to write a wrapper for operator<< that prepends some arbitrary information. What I have is: class Log : public std::ofstream { public: Log(const char *name) { this->open(name, std::ios::out | std::ios::ate); } ~Log() { if(*this) this->close(); } std::ofstream& operator<<(const char* text) { *((std::ofstream*)this) << "Date/Timestamp/Whatever: " << text; return *this; } }; I would like to have this worth with any type, though -- not just with const char* as the first data type sent to the log. How can I make this work with any data type? Is this possible or am I trying to do this in a backwards fashion? How is logging commonly handled in simple C++ games? Thanks in advance for any input/comments.