-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logging.h
52 lines (47 loc) · 1.42 KB
/
Logging.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
#pragma once
// define a function REMOTE_LOG_WRITE(char *) to use remote logging
extern void LOG_CALLBACK(char *);
static void LOG_REMOVE_NEWLINE(char *msg) {
int i = strlen(msg);
if (i > 0 && msg[i-1] == '\n') // remove trailing \n
msg[i-1] = 0;
};
#ifdef LOG_REMOTE
static void __FORMAT_LOG(const char* m, ...) {
char *logmsg;
va_list args;
va_start(args, m);
vasprintf(&logmsg, m, args);
LOG_CALLBACK(logmsg);
free(logmsg);
va_end(args);
};
#else
#define __FORMAT_LOG(...) Serial.printf(__VA_ARGS__)
#endif
#if not defined (LOG_LEVEL) || LOG_LEVEL == 0
#define ERROR(...)
#define INFO(...)
#define DEBUG(...)
#define DEBUG_BIN(...)
#elif LOG_LEVEL == 1
#define ERROR(...) __FORMAT_LOG(__VA_ARGS__)
#define INFO(...)
#define DEBUG(...)
#define DEBUG_BIN(...)
#elif LOG_LEVEL == 2
#define ERROR(...) __FORMAT_LOG(__VA_ARGS__)
#define INFO(...) __FORMAT_LOG(__VA_ARGS__)
#define DEBUG(...)
#define DEBUG_BIN(...)
#elif LOG_LEVEL == 3
#define ERROR(...) __FORMAT_LOG(__VA_ARGS__)
#define INFO(...) __FORMAT_LOG(__VA_ARGS__)
#define DEBUG(...) __FORMAT_LOG(__VA_ARGS__)
static void DEBUG_BIN(const char* m, uint8_t b[], int l) {
Serial.print(m);
for (int i=0; i<l;i++)
Serial.printf("%02X", b[i]);
Serial.println();
};
#endif