void wxFlybotDLL::OpenLog() { if (!wxLaunchDefaultApplication(GetLogFilename())) { // TODO: handle case when no program associated to .ini files } }
void LogFileInitialize(void) { FILE* f; const char* logFilename = GetLogFilename(); // It is valid for there to be no Log File. However since this // is the only place where the log file is initialized, we flag // it as something to note in the console. if (logFilename != NULL) { // Open for writing - this will overwrite any previous logfile fopen_s(&f, logFilename, "w+"); // read binary if (f != NULL) { fprintf(f, "Logging Started: %s\n\n", GetTimeStr().asCharArray()); fclose(f); } else { LogConsole(logERROR, "Unable to open logfile %s for writing \n", logFilename); } } }
void LogFileInitialize(const char* strFileName) { #ifndef DISABLE_LOG FILE* f = NULL; const char* logFilename; if (strFileName == NULL) { SP_strcpy(LogfilePath, SP_MAX_PATH, "c:\\splog.txt"); logFilename = GetLogFilename(); } else { logFilename = strFileName; SP_strcpy(LogfilePath, SP_MAX_PATH, strFileName); } // It is valid for there to be no Log File. However since this // is the only place where the log file is initialized, we flag // it as something to note in the console. if (logFilename != NULL) { // Open for writing - this will overwrite any previous logfile #ifdef _WIN32 fopen_s(&f, logFilename, "w+"); // read binary #else f = fopen(logFilename, "w+"); #endif if (f != NULL) { fprintf(f, "Logging Started: %s\n\n", StringUtils::GetTimeString().c_str()); fclose(f); } else { Log(logERROR, "Unable to open logfile %s for writing \n", logFilename); } } #ifdef WIN32 if (s_ConsoleAttached == false) { // ensure the log system is attached to a console // AttachConsole requires Win 2K or later. AttachConsole(ATTACH_PARENT_PROCESS); s_ConsoleAttached = true; } #endif #else SP_UNREFERENCED_PARAMETER(strFileName); #endif //DISABLE_LOG }
int main(int argc, char** argv) try { char LogFileName[MFile::MaxPath]; GetLogFilename(LogFileName, "MatchLog", "txt"); InitLog(MLOGSTYLE_DEBUGSTRING | MLOGSTYLE_FILE, LogFileName); void MatchServerCustomLog(const char*); CustomLog = MatchServerCustomLog; MCrashDump::SetCallback([](uintptr_t ExceptionInfo) { char Filename[MFile::MaxPath]; GetLogFilename(Filename, "MatchServer", "dmp"); MCrashDump::WriteDump(ExceptionInfo, Filename); }); MBMatchServer MatchServer; if (!MatchServer.Create(6000)) { MLog("MMatchServer::Create failed\n"); return -1; } MatchServer.InitLocator(); std::thread{ [&] { InputThreadProc(); } }.detach(); while (true) { MatchServer.Run(); HandleInput(MatchServer); std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } catch (std::runtime_error& e) { MLog("Uncaught std::runtime_error: %s\n", e.what()); throw; }
// // Write log messages into the logfile. // static void _logWriteW(const wchar_t* pMessage) { FILE* f = 0; const char* logFilename = GetLogFilename(); if (logFilename != NULL) { fopen_s(&f, logFilename, "a+"); // append if (f != NULL) { fwprintf(f, L"%s", pMessage); fclose(f); } } }
// // Write log messages into the logfile. // static void _logWrite(const char* pMessage) { FILE* f = 0; const char* logFilename = GetLogFilename(); if (logFilename != NULL) { #ifdef _WIN32 fopen_s(&f, logFilename, "a+"); // append #else f = fopen(logFilename, "a+"); #endif if (f != NULL) { fprintf(f, "%s", pMessage); fclose(f); } } }
// // Write log messages into the logfile. // static void _logWrite(const char* pMessage) { FILE* f; const char* logFilename = GetLogFilename(); if (logFilename != NULL) { if (LogMutexLock()) // wait for exclusive access to logfile { fopen_s(&f, logFilename, "a+"); // append if (f != NULL) { fprintf(f, "%s", pMessage); fclose(f); } else { #if defined (_WIN32) __declspec(thread) static bool recursiveWrite = false; // Avoid getting into an infinite loop if file can't be opened. #elif defined (_LINUX) static __thread bool recursiveWrite = false; // Avoid getting into an infinite loop if file can't be opened. #endif if (!recursiveWrite) { recursiveWrite = true; LogConsole(logERROR, "Unable to open logfile %s for append. Message Dropped = \n\t%s\n", logFilename, pMessage); recursiveWrite = false; } } LogMutexUnlock(); } } }
bool wxFlybotDLL::LogFileExists() { return wxFileExists(GetLogFilename()); }