1 Star 0 Fork 1

龙雨城/RH-android备份文件迁移

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
log.cpp 2.03 KB
一键复制 编辑 原始数据 按行查看 历史
龙雨城 提交于 2022-06-24 18:03 . 修改日志路径
#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;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/long-yucheng/rh-android-backup-file-parsing.git
git@gitee.com:long-yucheng/rh-android-backup-file-parsing.git
long-yucheng
rh-android-backup-file-parsing
RH-android备份文件迁移
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385