-
Notifications
You must be signed in to change notification settings - Fork 0
/
clogutil.cpp
78 lines (67 loc) · 1.35 KB
/
clogutil.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* CLogUtil.cpp
*
* Created on: Feb 16, 2020
* Author: acmax
*/
#include "clogutil.h"
#include <cstring>
#include <iostream>
extern "C"{
#include <stdarg.h>
#include <stdio.h>
}
CLogUtil::CLogUtil():
m_iLogLevel(eWTF){
// TODO Auto-generated constructor stub
}
CLogUtil::~CLogUtil() {
// TODO Auto-generated destructor stub
}
CLogUtil& CLogUtil::GetInstance(){
static CLogUtil stuLogUtil;
return stuLogUtil;
}
void CLogUtil::Log(int iLogLevel, const char* szFormat, ...){
if ( iLogLevel >= m_iLogLevel ){
int iLogStartIndex = 0;
AddLogLevelInfo(iLogLevel, iLogStartIndex);
va_list arglist;
va_start(arglist, szFormat);
vsprintf(&m_arrLogBuff[iLogStartIndex] ,szFormat, arglist);
va_end(arglist);
std::lock_guard<std::mutex> guard(m_LogMutex);
std::cout<<m_arrLogBuff<<std::endl;
}
else{
; //不需要记日志
}
}
void CLogUtil::AddLogLevelInfo(int iLogLevel, int& iLogStartIndex){
char const *pLogTag = NULL;
int iLogTagLen = 0;
switch(iLogLevel){
case eDebug:
pLogTag = "DEBUG: ";
iLogTagLen = 7;
break;
case eInfo:
pLogTag = "INFO: ";
iLogTagLen = 6;
break;
case eError:
pLogTag = "ERROR: ";
iLogTagLen = 7;
break;
case eWTF:
pLogTag = "WTF: ";
iLogTagLen = 5;
break;
default:
break;
}
if (iLogTagLen > 0 ){
memcpy(&m_arrLogBuff[0], pLogTag, iLogTagLen);
iLogStartIndex = iLogTagLen;
}
}