Hey everyone. I'm trying to create a logger for my program so that I can find very easily where the bugs occurs, what functions fail... but the problem is that my logger is failing, wich is pretty annoying since its purpose was to help me fix bugs... the problem is that it doesn't print ANYTHING to the file... but I verified and fstream::is_open() returns true... I also verified the string to output (with MessageBox) and its content is exactly what I wanted it to be... could someone tell me where I'm wrong ? This bug is really killing me since I really don't see anything that could lead to an error...
Code:
struct Log {
static void CreateLog();
static void Release();
static void Write(std::string, bool);
static void FormatString(std::string&, const char*, const char*, const UINT);
static std::fstream file;
};
void Log::CreateLog() {
file.open("log.txt");
}
void Log::Release() {
file.close();
}
void Log::Write(std::string argument, bool result) {
std::ostringstream oss;
oss << argument << "... " << (result ? "successful" : "failed") << '\n';
argument = oss.str();
MessageBox(0,argument.c_str(),0,0);
file << argument;
}
void Log::FormatString(std::string& buf, const char* argument, const char* file, const UINT line) {
std::ostringstream oss;
oss << argument << " in " << file << " on line " << line;
buf = oss.str();
}
Code:
std::string argument;
Log::FormatString(argument, "Creating Gdiplus::Pen object", __FILE__, __LINE__);
Log::Write(argument, (m_Pen = new Pen(Color(0,0,0))) != NULL);
Log::FormatString(argument, "Creating Gdiplus::Graphics object", __FILE__, __LINE__);
Log::Write(argument, (m_Graphics = new Graphics(hdc)) != NULL);
Thank you all.