-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.cpp
47 lines (40 loc) · 925 Bytes
/
Logger.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
#include<iostream>
#include<fstream>
#include<ctime>
#include"Logger.h"
using namespace std;
Logger::Logger()
{
//打开日志
m_fFd.open(LOG_PATH,ios::out|ios::app);
if(!m_fFd)
{
cout<<"error: open log file error"<<endl;
exit(-2);
}
time_t now_time=time(0);
m_fFd<<"\n*********************Start Log********************* TIME: "<<ctime(&now_time);
}
void Logger::writeLog(string str,LogType logType)
{
cout<<str<<endl;
string log_pre_text;
switch (logType)
{
case LogType::INFO:
log_pre_text="[INFO] ";
break;
case LogType::ERROR:
log_pre_text="[ERROR] ";
break;
case LogType::DEBUG:
log_pre_text="[DEBUG] ";
break;
default:
cout<<"log error."<<endl;
break;
}
time_t now_time=time(0);
m_fFd<<log_pre_text<<": "<<str<<" "<<ctime(&now_time);
return;
}