47 lines
1 KiB
C++
47 lines
1 KiB
C++
#include "FileLogger.h"
|
|
#include <time.h>
|
|
#include <iomanip>
|
|
|
|
|
|
FileLogger::~FileLogger()
|
|
{
|
|
|
|
}
|
|
|
|
void FileLogger::SetWorkDirectory(const std::string& workDir)
|
|
{
|
|
mWorkDirectory = workDir;
|
|
}
|
|
|
|
void FileLogger::SetFileName(const std::string& fileName)
|
|
{
|
|
mFileName = fileName;
|
|
}
|
|
|
|
void FileLogger::Open()
|
|
{
|
|
mFileStream.open(mWorkDirectory + "/" + mFileName);
|
|
}
|
|
|
|
void FileLogger::Close()
|
|
{
|
|
mFileStream.close();
|
|
}
|
|
|
|
void FileLogger::LogLine(const std::string& line)
|
|
{
|
|
mFileStream << line << std::endl;
|
|
}
|
|
|
|
void FileLogger::LogLine(const std::string& logType, const std::string& line, const std::string& fileName, const std::string& functionName, int lineNumber)
|
|
{
|
|
std::time_t t = std::time(nullptr);
|
|
const std::string cleanedFileName = fileName.substr(fileName.find_last_of("/\\") + 1);
|
|
std::tm time_buf = { 0 };
|
|
#ifdef WIN32
|
|
gmtime_s(&time_buf, &t);
|
|
#else
|
|
gmtime_r(&t, &time_buf);
|
|
#endif
|
|
mFileStream << logType << "|" << std::put_time(&time_buf, "%T") << "|" << cleanedFileName << "::" << functionName << "::" << lineNumber << "|" << line << std::endl;
|
|
}
|