Fixed error logger clearing file at all logs

This commit is contained in:
Pax1601 2024-07-22 17:57:16 +02:00
parent 62b2b13d75
commit 15e23564c2
2 changed files with 14 additions and 1 deletions

View File

@ -25,6 +25,7 @@ private:
mutex mutexLock;
void Clear();
void Open();
void Close();
};

View File

@ -19,6 +19,7 @@ Logger* Logger::GetLogger()
{
if (m_pThis == NULL) {
m_pThis = new Logger();
m_pThis->Clear();
}
return m_pThis;
}
@ -28,7 +29,7 @@ void Logger::setDirectory(string newDirPath)
m_dirPath = newDirPath;
}
void Logger::Open()
void Logger::Clear()
{
try {
m_Logfile.open((m_dirPath + m_sFileName).c_str(), ios::out | std::ios::trunc);
@ -39,6 +40,17 @@ void Logger::Open()
}
}
void Logger::Open()
{
try {
m_Logfile.open((m_dirPath + m_sFileName).c_str(), ios::out | std::ios::app);
}
catch (...) {
std::filesystem::path m_dirPath = std::filesystem::temp_directory_path();
m_Logfile.open((m_dirPath.string() + m_sFileName).c_str(), ios::out | std::ios::app);
}
}
void Logger::Close()
{
m_Logfile.close();