From f09cc3047080dee310ef0485eb9530fa8466cae9 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Tue, 7 Jun 2016 22:20:19 +0200 Subject: [PATCH] Add commandline argument (-d or --debug) to Windows Studio to log to file. Logger's option to logToFile now appends instead of overriding the old file from the day again. The first message logged to file also informs about the time, when logging to file started. --- build/windows/win32/PolycodeStudio/main.cpp | 10 ++++++++-- src/core/PolyLogger.cpp | 11 +++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/build/windows/win32/PolycodeStudio/main.cpp b/build/windows/win32/PolycodeStudio/main.cpp index bdab51b38..8a86faf1a 100644 --- a/build/windows/win32/PolycodeStudio/main.cpp +++ b/build/windows/win32/PolycodeStudio/main.cpp @@ -41,8 +41,7 @@ void registerFileType(String extension, String progId, String app, String defaul } -int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) -{ +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ ChangeWindowMessageFilter(WM_COPYDATA,MSGFLT_ADD); @@ -56,6 +55,13 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi fileName = fileName.replace("\\", "/"); + String arg; + for (int i = 1; i < nArgs; i++) { + arg = String(szArglist[i]); + if (arg == "-d" || arg == "--debug") + Logger::getInstance()->setLogToFile(true); + } + // check if an instance of Polycode is running and bring it up and open file if needed HWND runningHwnd = FindWindow(L"POLYCODEAPPLICATION", L"Polycode"); if(runningHwnd) { diff --git a/src/core/PolyLogger.cpp b/src/core/PolyLogger.cpp index b6c30a5a7..570af3f12 100644 --- a/src/core/PolyLogger.cpp +++ b/src/core/PolyLogger.cpp @@ -119,13 +119,16 @@ void Logger::setLogToFile(bool val){ time_t t = time(NULL); char mbstr[100]; if (strftime(mbstr, sizeof(mbstr), "%y_%m_%d.log", localtime(&t))) { - logFile = fopen((const char*)mbstr, "w"); + logFile = fopen((const char*)mbstr, "a"); } else { - logFile = fopen("poly.log", "w"); + logFile = fopen("poly.log", "a"); } + strftime(mbstr, sizeof(mbstr), "%y_%m_%d %H:%M", localtime(&t)); + logToFile = val; + Logger::log("== Starting Logging %s ==\n\n", mbstr); + } else { + logToFile = val; } - - logToFile = val; } void Logger::setLogFile(FILE *f){