-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.hpp
More file actions
76 lines (67 loc) · 1.66 KB
/
Logger.hpp
File metadata and controls
76 lines (67 loc) · 1.66 KB
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
#ifndef LOGGER_H
#define LOGGER_H
#pragma once
#include <string>
enum LoggerLevel {
INFO,//普通消息
ERROR,//错误消息
FATAL,//内核错误
DEBUG//调试消息
};
//LOG_INFO
#define LOG_INFO(logmsgFormat,...)\
do\
{\
Logger& logger=Logger::instance();\
logger.setLogLevel(INFO);\
char buf[1024]={0};\
snprintf(buf,1024,logmsgFormat,##__VA_ARGS__);\
logger.log(buf);\
}while(0)\
//LOG_ERROR
#define LOG_ERROR(logmsgFormat,...)\
do\
{\
Logger& logger=Logger::instance();\
logger.setLogLevel(ERROR);\
char buf[1024]={0};\
snprintf(buf,1024,logmsgFormat,##__VA_ARGS__);\
logger.log(buf);\
}while(0)\
//LOG_FATAL
#define LOG_FATAL(logmsgFormat,...)\
do\
{\
Logger& logger=Logger::instance();\
logger.setLogLevel(FATAL);\
char buf[1024]={0};\
snprintf(buf,1024,logmsgFormat,##__VA_ARGS__);\
logger.log(buf);\
exit(-1);\
}while(0)\
#ifdef MUDUODEBUG
//LOG_DEBUG
#define LOG_DEBUG(logmsgFormat,...)\
do\
{\
Logger& logger=Logger::instance();\
logger.setLogLevel(DEBUG);\
char buf[1024]={0};\
snprintf(buf,1024,logmsgFormat,##__VA_ARGS__);\
logger.log(buf);\
}while(0)\
#else
#define LOG_DEBUG(LogmsgFormat,...)
#endif
class Logger {
public:
static Logger& instance();//获取日志类实例
void setLogLevel(int level);
void log(std::string msg);//写日志
Logger(const Logger&) = delete;
Logger& operator=(const Logger&) = delete;
private:
int LoggerLevel_;
Logger() {};
};
#endif