-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.h
22 lines (19 loc) · 961 Bytes
/
debug.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef DEBUG_H
#define DEBUG_H
#include <stdio.h>
#include <time.h>
#include <errno.h>
#include <string.h>
#define TIME_FORMAT "%Y-%m-%d %H:%M:%S"
#define _LOG(color, tag, format, ...) \
do{ \
time_t now = time(NULL); \
char timestr[20] = {0}; \
strftime(timestr, 20, TIME_FORMAT, localtime(&now)); \
fprintf(stderr, color "[%s %s %d " tag "]: \e[0m" format , \
timestr, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
fflush(stderr); \
}while(0)
#define LOGD(format, ...) _LOG("\x1b[32m", "DEBUG", format, ##__VA_ARGS__)
#define LOGE(format, ...) _LOG("\x1b[31m", "ERROR", format, ##__VA_ARGS__)
#endif