Changed Log to set the log path once on application startup

This commit is contained in:
Leon Styhre 2023-12-15 18:35:02 +01:00
parent 56ccba81d1
commit 03e9035b7e
2 changed files with 6 additions and 10 deletions

View file

@ -22,16 +22,12 @@ void Log::setReportingLevel(LogLevel level)
sReportingLevel = level;
}
std::string Log::getLogPath()
{
return Utils::FileSystem::getHomePath() + "/.emulationstation/es_log.txt";
}
void Log::init()
{
Utils::FileSystem::removeFile(getLogPath() + ".bak");
sLogPath = Utils::FileSystem::getAppDataDirectory().append("es_log.txt");
Utils::FileSystem::removeFile(sLogPath.string() + ".bak");
// Rename the previous log file.
Utils::FileSystem::renameFile(getLogPath(), getLogPath() + ".bak", true);
Utils::FileSystem::renameFile(sLogPath.string(), sLogPath.string() + ".bak", true);
return;
}
@ -39,9 +35,9 @@ void Log::open()
{
std::unique_lock<std::mutex> lock {sLogMutex};
#if defined(_WIN64)
sFile.open(Utils::String::stringToWideString(getLogPath()).c_str());
sFile.open(Utils::String::stringToWideString(sLogPath.string()).c_str());
#else
sFile.open(getLogPath().c_str());
sFile.open(sLogPath.string().c_str());
#endif
}

View file

@ -47,7 +47,6 @@ public:
static void setReportingLevel(LogLevel level);
// These functions are not thread safe.
static std::string getLogPath();
static void init();
static void open();
@ -66,6 +65,7 @@ private:
static inline std::ofstream sFile;
static inline LogLevel sReportingLevel = LogInfo;
static inline std::mutex sLogMutex;
static inline std::filesystem::path sLogPath;
LogLevel mMessageLevel;
};