int CloseFileStream(wofstream &myfile) { if (myfile.is_open()) { myfile.flush(); myfile.close(); } return status_ok; }
int WriteFileRaw(wofstream &myfile, wstring resultData) { if (myfile.is_open()) { myfile << std::time(NULL) << L":" << resultData << endl; myfile.flush(); } else return status_query_failed; return status_ok; }
int OpenFileStream(wofstream &myfile, wstring fileName, bool recreate) { if (recreate) myfile.open(fileName, ios::out); else myfile.open(fileName, ios::out | ios::app); if (myfile.is_open()) { std::locale loc(std::locale::classic(), new std::codecvt_utf8<wchar_t>); myfile.imbue(loc); return status_ok; } else return status_io_error; }
bool Logger::openStream(wstring & path) { if(outLog) { outLog->flush(); delete outLog; } outLog = new wofstream(path); return outLog!=NULL; }
int WriteFileLog(wofstream &myfile, wstring data) { if (myfile.is_open()) { struct tm lt; time_t now_local = time(NULL); localtime_s(<, &now_local); wchar_t szBuf[2148] = L""; _snwprintf_s(szBuf, 2148, 2148, L"[%d-%02d-%02d %02d:%02d:%02d]: %s", lt.tm_year + 1900, lt.tm_mon + 1, lt.tm_mday, lt.tm_hour, lt.tm_min, lt.tm_sec, data.data()); myfile << szBuf << endl; #ifdef REC_TEST_CONSOLE wcout<< szBuf << endl; #endif myfile.flush(); } else return status_query_failed; return status_ok; }
void Logger::log(bool onlyVerbose,const wchar_t* format, ...) { if(!loggerOn||!outLog)return; if(onlyVerbose &!verbose)return; static wchar_t buffer[2048]; va_list argptr; va_start(argptr, format); vswprintf(buffer, 2048, format, argptr); va_end(argptr); std::wcout << buffer << L"\n"; (*outLog) << buffer << L"\n"; outLog->flush(); };