#include "Logger.h" Logger* Logger::m_instance = nullptr; Logger::Logger() { } Logger::~Logger() { } void Logger::WriteLog(int level, std::string logStr) { using namespace std::chrono; std::time_t tt = system_clock::to_time_t(system_clock::now()); auto microsecond = duration_cast(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(0) << " " << "time: " << ss.str() << " " << "logContent:" << logStr << std::endl; if (logfile.is_open()) { logfile.flush(); logfile.close(); } }