You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.2 KiB
C++
88 lines
2.2 KiB
C++
#include "LogManager.h"
|
|
|
|
|
|
LogManager* LogManager::m_instance = nullptr;
|
|
|
|
LogManager::LogManager()
|
|
{
|
|
}
|
|
|
|
|
|
LogManager::~LogManager()
|
|
{
|
|
}
|
|
|
|
void LogManager::WriteLog(LogType logType, std::string logStr)
|
|
{
|
|
using namespace std::chrono;
|
|
std::time_t tt = system_clock::to_time_t(system_clock::now());
|
|
auto microsecond = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count() % 1000000;
|
|
|
|
struct std::tm valtm;
|
|
localtime_s(&valtm, &tt);
|
|
|
|
std::stringstream ss;
|
|
ss << std::put_time(&valtm, "%F %X") << " " << microsecond / 1000;
|
|
std::cout << ss.str();
|
|
|
|
std::string timeStr = ss.str();
|
|
int findIndex = timeStr.find(" ");
|
|
std::string date = "none";
|
|
if (findIndex >= 0)
|
|
{
|
|
date = timeStr.substr(0, findIndex);
|
|
}
|
|
std::string fileName = "E:/WaferMark/code/WaferMark/Debug/log/" + date + ".txt";
|
|
|
|
|
|
std::ofstream logfile;
|
|
logfile.open(fileName, std::ios::app);
|
|
logfile << "logType: " << std::to_string(logType) << " " << "time: " << ss.str() << " " << "logContent:" << logStr << std::endl;
|
|
|
|
if (logfile.is_open())
|
|
{
|
|
logfile.flush();
|
|
logfile.close();
|
|
}
|
|
}
|
|
|
|
void LogManager::WriteLog(LogType logType, std::string DataName, std::vector<char>& dataContent)
|
|
{
|
|
std::string dataContentStr;
|
|
for (auto iter : dataContent)
|
|
{
|
|
std::string charStr(1,iter);
|
|
dataContentStr.append(charStr);
|
|
}
|
|
|
|
using namespace std::chrono;
|
|
std::time_t tt = system_clock::to_time_t(system_clock::now());
|
|
auto microsecond = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count() % 1000000;
|
|
|
|
struct std::tm valtm;
|
|
localtime_s(&valtm, &tt);
|
|
|
|
std::stringstream ss;
|
|
ss << std::put_time(&valtm, "%F %X") << " " << microsecond / 1000;
|
|
std::cout << ss.str();
|
|
|
|
std::string timeStr = ss.str();
|
|
int findIndex = timeStr.find(" ");
|
|
std::string date = "none";
|
|
if (findIndex >= 0)
|
|
{
|
|
date = timeStr.substr(0, findIndex);
|
|
}
|
|
std::string fileName = "E:/WaferMark/code/WaferMark/Debug/log/" + date + ".txt";
|
|
|
|
|
|
std::ofstream logfile;
|
|
logfile.open(fileName, std::ios::app);
|
|
logfile << "logType: " << std::to_string(logType) << " " << "time: " << ss.str() << " " << "logContent:" << dataContentStr << std::endl;
|
|
|
|
if (logfile.is_open())
|
|
{
|
|
logfile.flush();
|
|
logfile.close();
|
|
}
|
|
} |