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.
168 lines
4.2 KiB
C++
168 lines
4.2 KiB
C++
#include "QtLoggerManage.h"
|
|
|
|
QtLoggerManage::QtLoggerManage()
|
|
{
|
|
}
|
|
|
|
QtLoggerManage::~QtLoggerManage()
|
|
{
|
|
}
|
|
|
|
void QtLoggerManage::AddLog(QtLogType logType, std::string listName, QStringList list)
|
|
{
|
|
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 = m_logDir + date + ".txt";
|
|
|
|
|
|
std::ofstream logfile;
|
|
logfile.open(fileName, std::ios::app);
|
|
logfile << "logType: " << std::to_string(logType) << " "
|
|
<< " time: " << ss.str() << " "
|
|
<< " dataTypeName:" << listName<<" dataContent:";
|
|
for (auto& iter : list)
|
|
{
|
|
logfile << iter.toStdString() << ",";
|
|
}
|
|
logfile << std::endl;
|
|
|
|
if (logfile.is_open())
|
|
{
|
|
logfile.flush();
|
|
logfile.close();
|
|
}
|
|
}
|
|
|
|
void QtLoggerManage::AddLog(QtLogType logType, std::string logContent)
|
|
{
|
|
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 = m_logDir + date + ".txt";
|
|
|
|
|
|
std::ofstream logfile;
|
|
logfile.open(fileName, std::ios::app);
|
|
logfile << "logType: " << std::to_string(logType) << " "<< " time: " << ss.str() << " "<< " logContent:" << logContent <<std::endl;
|
|
|
|
if (logfile.is_open())
|
|
{
|
|
logfile.flush();
|
|
logfile.close();
|
|
}
|
|
}
|
|
|
|
void QtLoggerManage::AddLog(QtLogType 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 = m_logDir + 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();
|
|
}
|
|
}
|
|
|
|
void QtLoggerManage::AddLog(QtLogType logType, std::string logName, std::string logContent)
|
|
{
|
|
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 = m_logDir + date + ".txt";
|
|
|
|
|
|
std::ofstream logfile;
|
|
logfile.open(fileName, std::ios::app);
|
|
logfile << "logType: " << std::to_string(logType) << " "
|
|
<< " time: " << ss.str() << " "
|
|
<< " dataTypeName:" << logName <<
|
|
" dataContent:" << logContent << std::endl;
|
|
|
|
if (logfile.is_open())
|
|
{
|
|
logfile.flush();
|
|
logfile.close();
|
|
}
|
|
}
|
|
|
|
void QtLoggerManage::InitLogger(std::string logDir)
|
|
{
|
|
m_logDir = logDir;
|
|
}
|