src: replaced some usages of string by wstring in filepath

This commit is contained in:
mlangkabel
2018-02-26 15:03:28 +01:00
parent 6d82e9265a
commit bae6bd73d6
15 changed files with 66 additions and 76 deletions
+37 -8
View File
@@ -2,14 +2,43 @@
#include <fstream>
#include <sstream>
#include <ctime>
#include <cstdio>
#include "utility/file/FileSystem.h"
#include "utility/utilityString.h"
std::wstring FileLogger::generateDatedFileName(const std::wstring& prefix, const std::wstring& suffix)
{
time_t time;
std::time(&time);
tm t = *std::localtime(&time);
std::wstringstream filename;
if (!prefix.empty())
{
filename << prefix;
filename << L"_";
}
filename << t.tm_year + 1900 << L"-";
filename << (t.tm_mon < 9 ? L"0" : L"") << t.tm_mon + 1 << L"-";
filename << (t.tm_mday < 10 ? L"0" : L"") << t.tm_mday << L"_";
filename << (t.tm_hour < 10 ? L"0" : L"") << t.tm_hour << L"-";
filename << (t.tm_min < 10 ? L"0" : L"") << t.tm_min << L"-";
filename << (t.tm_sec < 10 ? L"0" : L"") << t.tm_sec;
if (!suffix.empty())
{
filename << L"_";
filename << suffix;
}
return filename.str();
}
FileLogger::FileLogger()
: Logger("FileLogger")
, m_logFileName("log")
, m_logFileName(L"log")
, m_logDirectory(L"user/log/")
, m_maxLogLineCount(0)
, m_maxLogFileCount(0)
@@ -31,7 +60,7 @@ FilePath FileLogger::getLogFilePath() const
void FileLogger::setLogFilePath(const FilePath& filePath)
{
m_currentLogFilePath = filePath;
m_logFileName = "";
m_logFileName = L"";
}
void FileLogger::setLogDirectory(const FilePath& filePath)
@@ -40,7 +69,7 @@ void FileLogger::setLogDirectory(const FilePath& filePath)
FileSystem::createDirectory(m_logDirectory);
}
void FileLogger::setFileName(const std::string& fileName)
void FileLogger::setFileName(const std::wstring& fileName)
{
if (fileName != m_logFileName)
{
@@ -78,17 +107,17 @@ void FileLogger::setMaxLogFileCount(unsigned int fileCount)
void FileLogger::updateLogFileName()
{
if (!m_logFileName.size())
if (m_logFileName.empty())
{
return;
}
bool fileChanged = false;
std::string currentLogFilePath = m_logDirectory.str() + m_logFileName;
std::wstring currentLogFilePath = m_logDirectory.wstr() + m_logFileName;
if (m_maxLogFileCount > 0)
{
currentLogFilePath += "_";
currentLogFilePath += L"_";
if (m_currentLogLineCount >= m_maxLogLineCount)
{
m_currentLogLineCount = 0;
@@ -100,10 +129,10 @@ void FileLogger::updateLogFileName()
}
fileChanged = true;
}
currentLogFilePath += std::to_string(m_currentLogFileCount);
currentLogFilePath += std::to_wstring(m_currentLogFileCount);
}
currentLogFilePath += ".txt";
currentLogFilePath += L".txt";
m_currentLogFilePath = FilePath(currentLogFilePath);
+4 -2
View File
@@ -10,6 +10,8 @@
class FileLogger: public Logger
{
public:
static std::wstring generateDatedFileName(const std::wstring& prefix = L"", const std::wstring& suffix = L"");
FileLogger();
virtual ~FileLogger();
@@ -17,7 +19,7 @@ public:
void setLogFilePath(const FilePath& filePath);
void setLogDirectory(const FilePath& filePath);
void setFileName(const std::string& fileName);
void setFileName(const std::wstring& fileName);
void setMaxLogLineCount(unsigned int logCount);
// setting the max log file count to 0 will disable ringlogging
@@ -31,7 +33,7 @@ private:
void logMessage(const std::string& type, const LogMessage& message);
void updateLogFileName();
std::string m_logFileName;
std::wstring m_logFileName;
FilePath m_logDirectory;
FilePath m_currentLogFilePath;
-32
View File
@@ -1,32 +0,0 @@
#include "LoggerUtility.h"
#include <sstream>
#include <ctime>
std::string LoggerUtility::generateDatedFileName(const std::string& prefix, const std::string& suffix)
{
time_t time;
std::time(&time);
tm t = *std::localtime(&time);
std::stringstream filename;
if (prefix.length() > 0)
{
filename << prefix;
filename << "_";
}
filename << t.tm_year + 1900 << "-";
filename << (t.tm_mon < 9 ? "0" : "") << t.tm_mon + 1 << "-";
filename << (t.tm_mday < 10 ? "0" : "") << t.tm_mday << "_";
filename << (t.tm_hour < 10 ? "0" : "") << t.tm_hour << "-";
filename << (t.tm_min < 10 ? "0" : "") << t.tm_min << "-";
filename << (t.tm_sec < 10 ? "0" : "") << t.tm_sec;
if (suffix.length() > 0)
{
filename << "_";
filename << suffix;
}
return filename.str();
}
-12
View File
@@ -1,12 +0,0 @@
#ifndef LOGGER_UTILITY_H
#define LOGGER_UTILITY_H
#include <string>
class LoggerUtility
{
public:
static std::string generateDatedFileName(const std::string& prefix = "", const std::string& suffix = "");
};
#endif // LOGGER_UTILITY_H