代码拉取完成,页面将自动刷新
#include "Log.h"
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <chrono>
#include "Clock.h"
MODULE_IMPL(nicehero::Log)
namespace nicehero
{
const int TIMEBUF_LENGTH = 12;
const int LOGBUF_MAXLEN = 1024 * 1024;
char LOGBUF[LOGBUF_MAXLEN + 1] = { 0 };
void Log::log(const char *msg, ...)
{
const int reservedLen = 1;//for \n
ui64 now = Clock::getInstance()->getTime();
#ifdef WIN32
tm tm_now;
localtime_s(&tm_now, (time_t*)&now);
strftime(m_timebuf, sizeof(m_timebuf), "[%H:%M:%S]: ", &tm_now);
strncpy(LOGBUF, m_timebuf, TIMEBUF_LENGTH);
#else
tm* tm_ = localtime((time_t*)&now);
strftime(m_timebuf, sizeof(m_timebuf), "[%H:%M:%S]: ", tm_);
strncpy(LOGBUF, m_timebuf, TIMEBUF_LENGTH);
#endif
const int size = LOGBUF_MAXLEN - TIMEBUF_LENGTH - reservedLen;
va_list args;
va_start(args, msg);
vsnprintf(LOGBUF + TIMEBUF_LENGTH, size, msg, args);
va_end(args);
puts(LOGBUF);
}
void Log::logerr(const char *msg, ...)
{
const int reservedLen = 1;//for \n
ui64 now = Clock::getInstance()->getTime();
#ifdef WIN32
tm tm_now;
localtime_s(&tm_now, (time_t*)&now);
strftime(m_timebuf, sizeof(m_timebuf), "[%H:%M:%S]: ", &tm_now);
strncpy(LOGBUF, m_timebuf, TIMEBUF_LENGTH);
#else
tm* tm_ = localtime((time_t*)&now);
strftime(m_timebuf, sizeof(m_timebuf), "[%H:%M:%S]: ", tm_);
strncpy(LOGBUF, m_timebuf, TIMEBUF_LENGTH);
#endif
const int size = LOGBUF_MAXLEN - TIMEBUF_LENGTH - reservedLen;
va_list args;
va_start(args, msg);
vsnprintf(LOGBUF + TIMEBUF_LENGTH, size, msg, args);
va_end(args);
puts(LOGBUF);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。