From 708242571bf75a38ac385121c3fd003ead6c4fb9 Mon Sep 17 00:00:00 2001 From: Alexander Aksenov Date: Thu, 25 Oct 2018 15:18:34 +0300 Subject: [PATCH] Logger: move file log to platform-dependent temp Signed-off-by: Alexander Aksenov --- src/debug/netcoredbg/logger.cpp | 4 +++- src/debug/netcoredbg/platform.cpp | 20 ++++++++++++++++++++ src/debug/netcoredbg/platform.h | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/debug/netcoredbg/logger.cpp b/src/debug/netcoredbg/logger.cpp index 1d95d37..dfa91d9 100644 --- a/src/debug/netcoredbg/logger.cpp +++ b/src/debug/netcoredbg/logger.cpp @@ -4,6 +4,7 @@ #include #include #include +#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() diff --git a/src/debug/netcoredbg/platform.cpp b/src/debug/netcoredbg/platform.cpp index 9bc0c98..2160c0d 100644 --- a/src/debug/netcoredbg/platform.cpp +++ b/src/debug/netcoredbg/platform.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #if defined(__APPLE__) #include @@ -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(); diff --git a/src/debug/netcoredbg/platform.h b/src/debug/netcoredbg/platform.h index 5b04246..5138928 100644 --- a/src/debug/netcoredbg/platform.h +++ b/src/debug/netcoredbg/platform.h @@ -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; -- 2.7.4