代码拉取完成,页面将自动刷新
#include "support.h"
char logFolder[0x500] = { 0 };
char logPath[0x500] = { 0 };
bool mLogInit = false;
void MakeAllPath(char* path)
{
char crePath[0x400] = { 0 };
char tmpPath[0x400] = { 0 };
sprintf(tmpPath, "%s", path);
for (unsigned int i = 0; i < strlen(tmpPath); i++)
{
if ('\\' == tmpPath[i])
{
memset(crePath, 0, 0x400);
memcpy(crePath, tmpPath, i + 1);
if (_access(crePath, 0))
_mkdir(crePath);
}
}
return;
}
void InitLog(char* logpath)
{
if (mLogInit)
return;
strcpy(logFolder, logpath);
strcat(logFolder, "ectLog\\PCData_Transfer\\");
MakeAllPath(logFolder);
mLogInit = true;
}
void GetSysTime(char* sysTime)
{
time_t t;
struct tm* lt;
time(&t); //获取Unix时间戳。
lt = localtime(&t); //转为时间结构。
char buf[0x20] = { 0 };
sprintf(buf, "%04d%02d%02d-%02d:%02d:%02d", lt->tm_year + 1900, lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec);
strcpy(sysTime, buf);
return;
}
void wlog(char* type, char* AMsg, const char* filename, int line)
{
if (!mLogInit)
return;
char* wAMsg = new char[LOG_LEN];
memset(wAMsg, 0, LOG_LEN);
char logdate[0x100] = { 0 };
time_t t;
time(&t);
struct tm* lt = localtime(&t);
sprintf(logdate, "%04d/%02d/%02d %02d:%02d:%02d", lt->tm_year + 1900, 1 + lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec);
//int min = 0, max = 100;
//std::random_device seed;//硬件生成随机数种子
//std::ranlux48 engine(seed());//利用种子生成随机数引擎
//std::uniform_int_distribution<> distrib(min, max);//设置随机数范围,并为均匀分布
//int random = distrib(engine);//随机数
sprintf_s(logPath, 0x100 - 1, "%sPCData_Transfer_%04d%02d%02d.log", logFolder, lt->tm_year + 1900, 1 + lt->tm_mon, lt->tm_mday);
FILE* fp;
fp = fopen(logPath, "ab+");
if (NULL == fp)
{
delete[]wAMsg;
wAMsg = NULL;
return;
}
fseek(fp, 0, SEEK_END);
strcat(wAMsg, logdate);
strcat(wAMsg, "\t");
sprintf(&wAMsg[20], "[%5s]\t[File:%30s - Line:%4d]\t%s\n", type, filename, line, AMsg);
fwrite(wAMsg, strlen(wAMsg), 1, fp);
fclose(fp);
delete[]wAMsg;
wAMsg = NULL;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。