8 Star 22 Fork 10

leo / supervisor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
logger.cc 940 Bytes
一键复制 编辑 原始数据 按行查看 历史
leo 提交于 2019-10-25 17:10 . 增加Windows平台支持
#include "logger.h"
#include <cstdarg>
#include <cstdio>
#include <ctime>
#include <memory>
using namespace std;
static const char LOG_TYPE_DESC[] = "EWIDCCCCCCCCCCCCCCCCCCCCCC";
Logger & Logger::Instance() {
static unique_ptr<Logger> _iIns;
if (!_iIns.get()) _iIns.reset(new Logger);
return *(_iIns.get());
}
void Logger::Log(ELog::Level emLevel, const char * pFmt, ...) {
std::unique_lock<std::mutex> iAuto(_iLock);
time_t nNow = time(NULL);
struct tm* pLocal = nullptr;
#if defined(_WIN32)
struct tm iLocal = { 0 };
pLocal = &iLocal;
localtime_s(pLocal, &nNow);
#else
pLocal = localtime(&nNow);
#endif
printf("[%04d-%02d-%02d %02d:%02d:%02d][%c] ",
pLocal->tm_year + 1900, pLocal->tm_mon + 1, pLocal->tm_mday, pLocal->tm_hour, pLocal->tm_min, pLocal->tm_sec,
LOG_TYPE_DESC[emLevel]);
va_list args;
va_start(args, pFmt);
vprintf(pFmt, args);
printf("\n");
va_end(args);
}
C++
1
https://gitee.com/love_linger/supervisor.git
git@gitee.com:love_linger/supervisor.git
love_linger
supervisor
supervisor
master

搜索帮助