forked from unhuman-io/motorlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.h
42 lines (38 loc) · 940 Bytes
/
logger.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
#ifndef UNHUMAN_MOTORLIB_LOGGER_H_
#define UNHUMAN_MOTORLIB_LOGGER_H_
#include <string>
#include <queue>
#include <stdarg.h>
class Logger {
public:
void log(std::string str) {
if (log_queue_.size() < 103) {
log_queue_.push(str);
}
}
void log_once(std::string str) {
if (str != log_queue_.back()) {
log(str);
}
}
std::string get_log() {
std::string str = "log end";
if (!log_queue_.empty()) {
str = log_queue_.front();
log_queue_.pop();
}
return str;
}
void log_printf(const char *s, ...) {
va_list args;
char sout[MAX_API_DATA_SIZE];
va_start(args, s);
vsnprintf(sout, MAX_API_DATA_SIZE, s, args);
va_end(args);
log(sout);
}
private:
std::queue<std::string> log_queue_ = {};
};
extern Logger logger;
#endif // UNHUMAN_MOTORLIB_LOGGER_H_