forked from Error323/E323AI
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCLogger.h
57 lines (40 loc) · 1.26 KB
/
CLogger.h
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
#ifndef LOGGER_H
#define LOGGER_H
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <map>
class AIClasses;
class CLogger {
public:
enum type { LOG_FILE = (1<<0), LOG_STDOUT = (1<<1), LOG_SPRING = (1<<2) };
CLogger(AIClasses *_ai, unsigned lt);
~CLogger() {}
/* Error logging */
void e(std::string msg) { log(ERROR, msg); }
/* Warning logging */
void w(std::string msg) { log(WARNING, msg); }
/* Verbose logging */
void v(std::string msg) { log(VERBOSE, msg); }
/* Log to spring */
void s(std::string msg);
private:
enum logLevel{ ERROR, WARNING, VERBOSE };
std::string fileName;
AIClasses *ai;
/* Sum of log type flags */
unsigned int logType;
/* File stream */
std::ofstream ofs;
/* logLevels to string */
std::map<logLevel, std::string> logLevels;
std::map<logLevel, std::string> logDesc;
/* Perform logging @ defined logTypes */
void log(logLevel level, std::string &msg);
};
#define LOG_EE(x) {std::stringstream ss; ss << x; ai->logger->e(ss.str());}
#define LOG_WW(x) {std::stringstream ss; ss << x; ai->logger->w(ss.str());}
#define LOG_II(x) {std::stringstream ss; ss << x; ai->logger->v(ss.str());}
#define LOG_SS(x) {std::stringstream ss; ss << x; ai->logger->s(ss.str());}
#endif