Logger: move file log to platform-dependent temp
authorAlexander Aksenov <a.aksenov@samsung.com>
Thu, 25 Oct 2018 12:18:34 +0000 (15:18 +0300)
committerAlexander Aksenov <a.aksenov@samsung.com>
Tue, 30 Oct 2018 09:40:49 +0000 (12:40 +0300)
Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
src/debug/netcoredbg/logger.cpp
src/debug/netcoredbg/platform.cpp
src/debug/netcoredbg/platform.h

index 1d95d37cd9e33b0d12ca40081a50c7479dc1c190..dfa91d93b54a89f4710956bc687be071cad756bf 100644 (file)
@@ -4,6 +4,7 @@
 #include <iomanip>
 #include <chrono>
 #include <stdio.h>
+#include "platform.h"
 #include "logger.h"
 
 #ifdef DEBUGGER_FOR_TIZEN
@@ -90,11 +91,12 @@ const std::string FileLogger::errorStr = "ERROR";
 FileLogger::FileLogger()
 {
     auto time = std::time(nullptr);
+    std::string tmpPath = GetTempFolder();
     std::ostringstream oss;
 
     oss << std::put_time(std::localtime(&time), "%Y_%m_%d__%H_%M_%S");
 
-    logFile = fopen(std::string(filenameBase + oss.str() + ".log").c_str(), "w+");
+    logFile = fopen(std::string(tmpPath + filenameBase + oss.str() + ".log").c_str(), "w+");
 }
 
 FileLogger::~FileLogger()
index 9bc0c989a6ea80dfcf5051b6a250ce14b7297114..2160c0d6e1faeb7bc5797dd38e1706649a34295f 100644 (file)
@@ -28,6 +28,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
+#include <stdlib.h>
 
 #if defined(__APPLE__)
 #include <mach-o/dyld.h>
@@ -793,6 +794,25 @@ void IORedirectServerHandles::RedirectOutput(
 
 #endif
 
+std::string GetTempFolder()
+{
+#ifdef WIN32
+    CHAR path[MAX_PATH];
+    DWORD len = GetTempPathA(MAX_PATH - 1, path);
+    return std::string(path, len);
+#elif __APPLE__
+    char *pPath = getenv("TMPDIR");
+
+    if (pPath != nullptr)
+        return std::string(pPath);
+    else
+        return "";
+#else //WIN32
+    return "/tmp/";
+#endif // WIN32
+}
+
+
 IORedirectServer::operator bool() const
 {
     return m_handles->IsConnected();
index 5b04246d4b128f88030113f78124baa9f9596bd9..5138928d893984ad3c6246aac4628eb9827c6ad8 100644 (file)
@@ -18,6 +18,7 @@ void USleep(uint32_t duration);
 void *DLOpen(const std::string &path);
 void *DLSym(void *handle, const std::string &name);
 void UnsetCoreCLREnv();
+std::string GetTempFolder();
 
 class IORedirectServerHandles;