-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmyLogging.cpp
More file actions
80 lines (60 loc) · 1.47 KB
/
myLogging.cpp
File metadata and controls
80 lines (60 loc) · 1.47 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "myConfig.h"
#include "myLogging.h"
#include <SimpleSyslog.h> // https://github.com/scottchiefbaker/Arduino-SimpleSyslog
SimpleSyslog* syslog;
extern Config config;
void logging(int severity, const char* format, va_list args) {
char* message;
vasprintf(&message, format, args);
if (syslog == 0) {
if (strlen(config.syslog_server) > 1) {
syslog = new SimpleSyslog(getAPName(), APPLICATION_NAME, config.syslog_server);
}
}
char* severityMsg;
switch(severity) {
case PRI_ERROR:
severityMsg = "ERROR";
break;
case PRI_WARNING:
severityMsg = "WARNING";
break;
case PRI_INFO:
severityMsg = "INFO";
break;
case PRI_DEBUG:
severityMsg = "DEBUG";
break;
default:
severityMsg = "UNKNOWN";
}
Serial.printf("[%s] %s\n", severityMsg, message);
if (syslog != 0) {
syslog->printf(FAC_LOCAL7, severity, message);
}
free(message);
}
void debugLog(const char* format, ...) {
va_list args;
va_start(args, format);
logging(PRI_DEBUG, format, args);
va_end(args);
}
void infoLog(const char* format, ...) {
va_list args;
va_start(args, format);
logging(PRI_INFO, format, args);
va_end(args);
}
void warningLog(const char* format, ...) {
va_list args;
va_start(args, format);
logging(PRI_WARNING, format, args);
va_end(args);
}
void errorLog(const char* format, ...) {
va_list args;
va_start(args, format);
logging(PRI_ERROR, format, args);
va_end(args);
}