代码拉取完成,页面将自动刷新
#include "debug_log.h"
void DEBUG_LOG(const char* msg, ...) {
char message[256] = { 0 };
va_list args;
va_start(args, msg);
vsprintf(message, msg, args);
va_end(args);
Debug_LOG::log()->write_log(message);
}
Debug_LOG* Debug_LOG::m_log = NULL;
Debug_LOG::Debug_LOG() :
tim(0),
t(NULL),
fp(NULL),
filepath(),
message(),
last_log_time()
{
#ifdef __WRITE_FILE__
create_log_file();
#endif
}
Debug_LOG::~Debug_LOG() {
#ifdef __WRITE_FILE__
fclose(fp);
#endif
}
void Debug_LOG::create_log_file() {
if (fp != NULL)
fclose(fp);
sprintf(filepath, "./log/debuglog_");
time(&tim);
t = localtime(&tim);
memcpy(&last_log_time, t, sizeof(struct tm));
sprintf(filepath + 15, "%02d_%02d", t->tm_mon + 1, t->tm_mday);
fp = fopen(filepath, "a+");
}
Debug_LOG* Debug_LOG::log() {
if (m_log == NULL) {
m_log = new Debug_LOG();
}
return m_log;
}
void Debug_LOG::write_log(const char* msg) {
time(&tim);
t = localtime(&tim);
sprintf(message, "[%02d:%02d:%02d] %s\n", t->tm_hour, t->tm_min, t->tm_sec, msg);
#ifdef __WRITE_FILE__
if (t->tm_mday != last_log_time.tm_mday || t->tm_mon != last_log_time.tm_mon
|| t->tm_year != last_log_time.tm_year)
create_log_file();
fwrite(message, strlen(message), 1, fp);
fflush(fp);
#else
printf("\n%s", message);
fflush(stdout);
#endif
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。