-
Notifications
You must be signed in to change notification settings - Fork 2
/
logger.cpp
51 lines (44 loc) · 983 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
48
49
50
51
#include "logger.h"
#include <iostream>
#include <time.h>
#include <cstdio>
using namespace std;
Logger::Logger()
{
}
char* Logger::getNow()
{
// 获取时间戳
time_t tt = time(NULL);
// 转换为本地时间
tm* t= localtime(&tt);
char* formatTime;
sprintf(formatTime,"%d-%02d-%02d %02d:%02d:%02d",
t->tm_year + 1900,
t->tm_mon + 1,
t->tm_mday,
t->tm_hour,
t->tm_min,
t->tm_sec);
return formatTime;
}
void Logger::log(string msg)
{
char* now = this->getNow();
cout << "[LOG]" << now << "::" << msg << endl;
}
void Logger::info(string msg)
{
char* now = this->getNow();
cout << "[INFO]" << now << "::" << msg << endl;
}
void Logger::warn(string msg)
{
char* now = this->getNow();
cout << "[WARN]" << now << "::" << msg << endl;
}
void Logger::error(string msg)
{
char* now = this->getNow();
cout << "[ERROR]" << now << "::" << msg << endl;
}