-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlogger.h
38 lines (28 loc) · 1.11 KB
/
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
#ifndef LOGGER_H
#define LOGGER_H
#include "logger.h"
typedef enum LogLevel { ALWAYS, ERROR, WARN, INFO, DEBUG } LogLevel;
void logger_init(const char *path, LogLevel stdout_lvl, LogLevel file_lvl);
void logger(LogLevel lvl, const char *str, const char *file, int line);
#ifndef __ANDROID__
void print_trace(void);
#endif
#define LOG(lvl, format, args...) \
{ \
char _buf[1024]; \
snprintf(_buf, sizeof(_buf), format, ##args); \
logger(lvl, _buf, __FILE__, __LINE__); \
}
#ifdef __ANDROID__
#define LOG_FUNC_ERROR LOG(ERROR, "%s failed.", __func__)
#else
#define LOG_FUNC_ERROR \
{ \
LOG(ERROR, "%s failed.", __func__) \
print_trace(); \
}
#endif
#define LOG_FUNC_WARN LOG(WARN, "%s", __func__)
#define LOG_FUNC_INFO LOG(INFO, "%s", __func__)
#define D(format, args...) LOG(ALWAYS, format, ##args)
#endif